From dbdb8d5069bb50884a3af07ed23160b63fcf567c Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Wed, 8 Nov 2023 22:07:27 +0100 Subject: [PATCH 1/5] BLD: Fix features.h detection for Meson builds Fixes function blocklisting for glibc<2.18, reported in issue gh-25087. Signed-off-by: Marcel Bargull --- numpy/_core/config.h.in | 1 + 1 file changed, 1 insertion(+) diff --git a/numpy/_core/config.h.in b/numpy/_core/config.h.in index 9c17990d3331..7ef169c44427 100644 --- a/numpy/_core/config.h.in +++ b/numpy/_core/config.h.in @@ -12,6 +12,7 @@ #mesondefine HAVE___DECLSPEC_THREAD_ /* Optional headers */ +#mesondefine HAVE_FEATURES_H #mesondefine HAVE_XLOCALE_H #mesondefine HAVE_DLFCN_H #mesondefine HAVE_EXECINFO_H From 1d9a6f43f07683ac86746af9216ec294e3b10109 Mon Sep 17 00:00:00 2001 From: mattip Date: Thu, 9 Nov 2023 13:13:27 +0200 Subject: [PATCH 2/5] TST: add a test --- numpy/_core/tests/test_umath.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/numpy/_core/tests/test_umath.py b/numpy/_core/tests/test_umath.py index 39a4f7534e50..1e32d8c54cca 100644 --- a/numpy/_core/tests/test_umath.py +++ b/numpy/_core/tests/test_umath.py @@ -1712,6 +1712,9 @@ def test_arctanh(self): assert_raises(FloatingPointError, np.arctanh, np.array(value, dtype=dt)) + # Make sure glibc < 2.18 atanh is not used, issue 25087 + assert np.signbit(np.arctanh(-1j).real) + # See: https://github.com/numpy/numpy/issues/20448 @pytest.mark.xfail( _glibc_older_than("2.17"), From cab680cc226534e245c0d3d1a36ae711658da2a6 Mon Sep 17 00:00:00 2001 From: mattip Date: Thu, 9 Nov 2023 15:01:17 +0200 Subject: [PATCH 3/5] BLD: blocklist complex trig functions on musl Signed-off-by: mattip --- numpy/_core/src/common/npy_config.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/numpy/_core/src/common/npy_config.h b/numpy/_core/src/common/npy_config.h index 715b17777aed..e590366888aa 100644 --- a/numpy/_core/src/common/npy_config.h +++ b/numpy/_core/src/common/npy_config.h @@ -160,8 +160,29 @@ #undef HAVE_CACOSHL #endif /* __GLIBC_PREREQ(2, 18) */ -#endif /* defined(__GLIBC_PREREQ) */ +#else /* defined(__GLIBC) */ +/* musl linux?, see issue #25092 */ +#undef HAVE_CASIN +#undef HAVE_CASINF +#undef HAVE_CASINL +#undef HAVE_CASINH +#undef HAVE_CASINHF +#undef HAVE_CASINHL +#undef HAVE_CATAN +#undef HAVE_CATANF +#undef HAVE_CATANL +#undef HAVE_CATANH +#undef HAVE_CATANHF +#undef HAVE_CATANHL +#undef HAVE_CACOS +#undef HAVE_CACOSF +#undef HAVE_CACOSL +#undef HAVE_CACOSH +#undef HAVE_CACOSHF +#undef HAVE_CACOSHL + +#endif /* defined(__GLIBC) */ #endif /* defined(HAVE_FEATURES_H) */ #endif /* NUMPY_CORE_SRC_COMMON_NPY_CONFIG_H_ */ From c77ab476df4cd008cb180c62c24a5098a31ea782 Mon Sep 17 00:00:00 2001 From: mattip Date: Thu, 9 Nov 2023 16:09:04 +0200 Subject: [PATCH 4/5] unskip musl complex trig tests --- numpy/_core/tests/test_umath.py | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/numpy/_core/tests/test_umath.py b/numpy/_core/tests/test_umath.py index 1e32d8c54cca..87ecc90a2bdf 100644 --- a/numpy/_core/tests/test_umath.py +++ b/numpy/_core/tests/test_umath.py @@ -17,8 +17,7 @@ assert_, assert_equal, assert_raises, assert_raises_regex, assert_array_equal, assert_almost_equal, assert_array_almost_equal, assert_array_max_ulp, assert_allclose, assert_no_warnings, suppress_warnings, - _gen_alignment_data, assert_array_almost_equal_nulp, IS_WASM, IS_MUSL, - IS_PYPY + _gen_alignment_data, assert_array_almost_equal_nulp, IS_WASM, IS_PYPY ) from numpy.testing._private.utils import _glibc_older_than @@ -1354,21 +1353,9 @@ def test_log_values(self): # test log() of max for dtype does not raise for dt in ['f', 'd', 'g']: - try: - with np.errstate(all='raise'): - x = np.finfo(dt).max - np.log(x) - except FloatingPointError as exc: - if dt == 'g' and IS_MUSL: - # FloatingPointError is known to occur on longdouble - # for musllinux_x86_64 x is very large - pytest.skip( - "Overflow has occurred for" - " np.log(np.finfo(np.longdouble).max)" - ) - else: - raise exc - + with np.errstate(all='raise'): + x = np.finfo(dt).max + np.log(x) def test_log_strides(self): np.random.seed(42) strides = np.array([-4,-3,-2,-1,1,2,3,4]) @@ -1899,7 +1886,6 @@ def test_ldexp(self, dtype, stride): class TestFRExp: @pytest.mark.parametrize("stride", [-4,-2,-1,1,2,4]) @pytest.mark.parametrize("dtype", ['f', 'd']) - @pytest.mark.xfail(IS_MUSL, reason="gh23048") @pytest.mark.skipif(not sys.platform.startswith('linux'), reason="np.frexp gives different answers for NAN/INF on windows and linux") def test_frexp(self, dtype, stride): @@ -4138,7 +4124,6 @@ def test_it(self): assert_almost_equal(fz.real, fr, err_msg='real part %s' % f) assert_almost_equal(fz.imag, 0., err_msg='imag part %s' % f) - @pytest.mark.xfail(IS_MUSL, reason="gh23049") @pytest.mark.xfail(IS_WASM, reason="doesn't work") def test_precisions_consistent(self): z = 1 + 1j @@ -4149,7 +4134,6 @@ def test_precisions_consistent(self): assert_almost_equal(fcf, fcd, decimal=6, err_msg='fch-fcd %s' % f) assert_almost_equal(fcl, fcd, decimal=15, err_msg='fch-fcl %s' % f) - @pytest.mark.xfail(IS_MUSL, reason="gh23049") @pytest.mark.xfail(IS_WASM, reason="doesn't work") def test_branch_cuts(self): # check branch cuts and continuity on them @@ -4176,7 +4160,6 @@ def test_branch_cuts(self): _check_branch_cut(np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1) _check_branch_cut(np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1) - @pytest.mark.xfail(IS_MUSL, reason="gh23049") @pytest.mark.xfail(IS_WASM, reason="doesn't work") def test_branch_cuts_complex64(self): # check branch cuts and continuity on them @@ -4230,7 +4213,6 @@ def test_against_cmath(self): _glibc_older_than("2.18"), reason="Older glibc versions are imprecise (maybe passes with SIMD?)" ) - @pytest.mark.xfail(IS_MUSL, reason="gh23049") @pytest.mark.xfail(IS_WASM, reason="doesn't work") @pytest.mark.parametrize('dtype', [ np.complex64, np.complex128, np.clongdouble From 9ea36bf498fd1540ac79f2a2637fe01a9d79998b Mon Sep 17 00:00:00 2001 From: mattip Date: Thu, 9 Nov 2023 16:22:20 +0200 Subject: [PATCH 5/5] frexp is still not right on musl --- numpy/_core/tests/test_umath.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/numpy/_core/tests/test_umath.py b/numpy/_core/tests/test_umath.py index 87ecc90a2bdf..aa8e1097149a 100644 --- a/numpy/_core/tests/test_umath.py +++ b/numpy/_core/tests/test_umath.py @@ -17,7 +17,8 @@ assert_, assert_equal, assert_raises, assert_raises_regex, assert_array_equal, assert_almost_equal, assert_array_almost_equal, assert_array_max_ulp, assert_allclose, assert_no_warnings, suppress_warnings, - _gen_alignment_data, assert_array_almost_equal_nulp, IS_WASM, IS_PYPY + _gen_alignment_data, assert_array_almost_equal_nulp, IS_WASM, IS_MUSL, + IS_PYPY ) from numpy.testing._private.utils import _glibc_older_than @@ -1888,6 +1889,7 @@ class TestFRExp: @pytest.mark.parametrize("dtype", ['f', 'd']) @pytest.mark.skipif(not sys.platform.startswith('linux'), reason="np.frexp gives different answers for NAN/INF on windows and linux") + @pytest.mark.xfail(IS_MUSL, reason="gh23049") def test_frexp(self, dtype, stride): arr = np.array([np.nan, np.nan, np.inf, -np.inf, 0.0, -0.0, 1.0, -1.0], dtype=dtype) mant_true = np.array([np.nan, np.nan, np.inf, -np.inf, 0.0, -0.0, 0.5, -0.5], dtype=dtype)