Skip to content

TST: move get_glibc_version to np.testing; skip 2 more tests for old glibc #20558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions numpy/core/tests/test_umath.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,8 @@
assert_array_max_ulp, assert_allclose, assert_no_warnings, suppress_warnings,
_gen_alignment_data, assert_array_almost_equal_nulp
)
from numpy.testing._private.utils import _glibc_older_than

def get_glibc_version():
try:
ver = os.confstr('CS_GNU_LIBC_VERSION').rsplit(' ')[1]
except Exception as inst:
ver = '0.0'

return ver


glibcver = get_glibc_version()
glibc_older_than = lambda x: (glibcver != '0.0' and glibcver < x)

def on_powerpc():
""" True if we are running on a Power PC platform."""
Expand Down Expand Up @@ -1014,7 +1004,7 @@ def test_exp_values(self):

# 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):
Expand Down Expand Up @@ -1262,6 +1252,11 @@ def test_arctanh(self):
assert_raises(FloatingPointError, np.arctanh,
np.array(value, dtype=dt))

# See: https://github.com/numpy/numpy/issues/20448
@pytest.mark.xfail(
_glibc_older_than("2.17"),
reason="Older glibc versions may not raise appropriate FP exceptions"
)
def test_exp2(self):
with np.errstate(all='ignore'):
in_ = [np.nan, -np.nan, np.inf, -np.inf]
Expand Down Expand Up @@ -1397,7 +1392,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))
Expand Down
5 changes: 4 additions & 1 deletion numpy/core/tests/test_umath_accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import pytest
from ctypes import c_longlong, c_double, c_float, c_int, cast, pointer, POINTER
from numpy.testing import assert_array_max_ulp
from numpy.testing._private.utils import _glibc_older_than
from numpy.core._multiarray_umath import __cpu_features__

IS_AVX = __cpu_features__.get('AVX512F', False) or \
(__cpu_features__.get('FMA3', False) and __cpu_features__.get('AVX2', False))
runtest = sys.platform.startswith('linux') and IS_AVX
# only run on linux with AVX, also avoid old glibc (numpy/numpy#20448).
runtest = (sys.platform.startswith('linux')
and IS_AVX and not _glibc_older_than("2.17"))
platform_skip = pytest.mark.skipif(not runtest,
reason="avoid testing inconsistent platform "
"library implementations")
Expand Down
13 changes: 13 additions & 0 deletions numpy/testing/_private/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2518,3 +2518,16 @@ def wrapper(*args, **kwargs):
finally:
sys.settrace(original_trace)
return wrapper


def _get_glibc_version():
try:
ver = os.confstr('CS_GNU_LIBC_VERSION').rsplit(' ')[1]
except Exception as inst:
ver = '0.0'

return ver


_glibcver = _get_glibc_version()
_glibc_older_than = lambda x: (_glibcver != '0.0' and _glibcver < x)