From 01443e8d32dd586ac27fe5aebe1a781460190e6a Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Tue, 2 Nov 2021 14:18:52 +1100 Subject: [PATCH 1/4] TST: turn glibc_older_than_2.17 into boolean instead of xfail this anticipates reuse of this boolean within the test module --- numpy/core/tests/test_umath.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index 8f5a858249e9..2f7322412e01 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -28,9 +28,7 @@ def get_glibc_version(): glibcver = get_glibc_version() -glibc_newerthan_2_17 = pytest.mark.xfail( - glibcver != '0.0' and glibcver < '2.17', - reason="Older glibc versions may not raise appropriate FP exceptions") +glibc_older_than_2_17 = (glibcver != '0.0' and glibcver < '2.17') def on_powerpc(): """ True if we are running on a Power PC platform.""" @@ -1024,7 +1022,10 @@ def test_exp_values(self): # Older version of glibc may not raise the correct FP exceptions # See: https://github.com/numpy/numpy/issues/19192 - @glibc_newerthan_2_17 + @pytest.mark.xfail( + glibc_older_than_2_17, + reason="Older glibc versions may not raise appropriate FP exceptions" + ) def test_exp_exceptions(self): with np.errstate(over='raise'): assert_raises(FloatingPointError, np.exp, np.float32(100.)) From 56268d5cf8ded5ebe0b51cca6c23da4b0586807c Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Tue, 2 Nov 2021 14:19:24 +1100 Subject: [PATCH 2/4] TST: use existence of glibc-version to clean up a test --- numpy/core/tests/test_umath.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index 2f7322412e01..ffe653d18a0e 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -48,14 +48,6 @@ def bad_arcsinh(): # The eps for float128 is 1-e33, so this is way bigger return abs((v1 / v2) - 1.0) > 1e-23 -if platform.machine() == 'aarch64' and bad_arcsinh(): - skip_longcomplex_msg = ('Trig functions of np.longcomplex values known to be ' - 'inaccurate on aarch64 for some compilation ' - 'configurations, should be fixed by building on a ' - 'platform using glibc>2.17') -else: - skip_longcomplex_msg = '' - class _FilterInvalids: def setup(self): @@ -3440,13 +3432,14 @@ def check(x, rtol): x_series = np.logspace(-20, -3.001, 200) x_basic = np.logspace(-2.999, 0, 10, endpoint=False) - if dtype is np.longcomplex: + if glibc_older_than_2_17 and dtype is np.longcomplex: + if (platform.machine() == 'aarch64' and bad_arcsinh()): + pytest.skip("Trig functions of np.longcomplex values known " + "to be inaccurate on aarch64 for some compilation " + "configurations.") # It's not guaranteed that the system-provided arc functions # are accurate down to a few epsilons. (Eg. on Linux 64-bit) # So, give more leeway for long complex tests here: - # Can use 2.1 for > Ubuntu LTS Trusty (2014), glibc = 2.19. - if skip_longcomplex_msg: - pytest.skip(skip_longcomplex_msg) check(x_series, 50.0*eps) else: check(x_series, 2.1*eps) From 12923c259c71ad0601a49ecc3de4748adaba0957 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Tue, 2 Nov 2021 14:21:01 +1100 Subject: [PATCH 3/4] TST: skip coverage of large elements in sincos_float32 for ancient glibc Fixes #15179 --- numpy/core/tests/test_umath.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index ffe653d18a0e..b04faecb90da 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -1398,8 +1398,10 @@ def test_sincos_float32(self): M = np.int_(N/20) index = np.random.randint(low=0, high=N, size=M) x_f32 = np.float32(np.random.uniform(low=-100.,high=100.,size=N)) - # test coverage for elements > 117435.992f for which glibc is used - x_f32[index] = np.float32(10E+10*np.random.rand(M)) + if not glibc_older_than_2_17: + # test coverage for elements > 117435.992f for which glibc is used + # this is known to be problematic on old glibc, so skip it there + x_f32[index] = np.float32(10E+10*np.random.rand(M)) x_f64 = np.float64(x_f32) assert_array_max_ulp(np.sin(x_f32), np.float32(np.sin(x_f64)), maxulp=2) assert_array_max_ulp(np.cos(x_f32), np.float32(np.cos(x_f64)), maxulp=2) From 22448b4247bec30ef4bd4d6f649a234ddb1f4cdd Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Tue, 2 Nov 2021 16:51:59 +1100 Subject: [PATCH 4/4] TST: parametrize glibc-version check in test_umath.py --- numpy/core/tests/test_umath.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py index b04faecb90da..fc7c592f05f6 100644 --- a/numpy/core/tests/test_umath.py +++ b/numpy/core/tests/test_umath.py @@ -28,7 +28,7 @@ def get_glibc_version(): glibcver = get_glibc_version() -glibc_older_than_2_17 = (glibcver != '0.0' and glibcver < '2.17') +glibc_older_than = lambda x: (glibcver != '0.0' and glibcver < x) def on_powerpc(): """ True if we are running on a Power PC platform.""" @@ -1012,10 +1012,9 @@ def test_exp_values(self): yf = np.array(y, dtype=dt) assert_equal(np.exp(yf), xf) - # Older version of glibc may not raise the correct FP exceptions # See: https://github.com/numpy/numpy/issues/19192 @pytest.mark.xfail( - glibc_older_than_2_17, + glibc_older_than("2.17"), reason="Older glibc versions may not raise appropriate FP exceptions" ) def test_exp_exceptions(self): @@ -1398,7 +1397,7 @@ def test_sincos_float32(self): M = np.int_(N/20) index = np.random.randint(low=0, high=N, size=M) x_f32 = np.float32(np.random.uniform(low=-100.,high=100.,size=N)) - if not glibc_older_than_2_17: + if not glibc_older_than("2.17"): # test coverage for elements > 117435.992f for which glibc is used # this is known to be problematic on old glibc, so skip it there x_f32[index] = np.float32(10E+10*np.random.rand(M)) @@ -3434,7 +3433,7 @@ def check(x, rtol): x_series = np.logspace(-20, -3.001, 200) x_basic = np.logspace(-2.999, 0, 10, endpoint=False) - if glibc_older_than_2_17 and dtype is np.longcomplex: + if glibc_older_than("2.19") and dtype is np.longcomplex: if (platform.machine() == 'aarch64' and bad_arcsinh()): pytest.skip("Trig functions of np.longcomplex values known " "to be inaccurate on aarch64 for some compilation "