diff --git a/numpy/_core/tests/test_scalar_methods.py b/numpy/_core/tests/test_scalar_methods.py index 3cb00dc6ab64..6630e722b37d 100644 --- a/numpy/_core/tests/test_scalar_methods.py +++ b/numpy/_core/tests/test_scalar_methods.py @@ -3,7 +3,6 @@ """ import fractions import inspect -import platform import sys import types from typing import Any, Literal @@ -13,6 +12,7 @@ import numpy as np from numpy._core import sctypes from numpy.testing import assert_equal, assert_raises +from numpy.testing._private.utils import LONG_DOUBLE_IS_IBM_DOUBLE_DOUBLE class TestAsIntegerRatio: @@ -87,7 +87,7 @@ def test_against_known_values(self): np.finfo(np.double) == np.finfo(np.longdouble), reason="long double is same as double"), pytest.mark.skipif( - platform.machine().startswith("ppc"), + LONG_DOUBLE_IS_IBM_DOUBLE_DOUBLE, reason="IBM double double"), ] ) diff --git a/numpy/_core/tests/test_scalarmath.py b/numpy/_core/tests/test_scalarmath.py index 877ea8b8ffba..c465b90f85c7 100644 --- a/numpy/_core/tests/test_scalarmath.py +++ b/numpy/_core/tests/test_scalarmath.py @@ -23,6 +23,7 @@ assert_raises, check_support_sve, ) +from numpy.testing._private.utils import LONG_DOUBLE_IS_IBM_DOUBLE_DOUBLE types = [np.bool, np.byte, np.ubyte, np.short, np.ushort, np.intc, np.uintc, np.int_, np.uint, np.longlong, np.ulonglong, @@ -521,7 +522,7 @@ def test_int_from_infinite_longdouble(self): @pytest.mark.skipif(np.finfo(np.double) == np.finfo(np.longdouble), reason="long double is same as double") - @pytest.mark.skipif(platform.machine().startswith("ppc"), + @pytest.mark.skipif(LONG_DOUBLE_IS_IBM_DOUBLE_DOUBLE, reason="IBM double double") def test_int_from_huge_longdouble(self): # Produce a longdouble that would overflow a double, diff --git a/numpy/_core/tests/test_scalarprint.py b/numpy/_core/tests/test_scalarprint.py index 38ed7780f2e6..7d5ce3004dff 100644 --- a/numpy/_core/tests/test_scalarprint.py +++ b/numpy/_core/tests/test_scalarprint.py @@ -1,12 +1,12 @@ """ Test printing of scalar types. """ -import platform import pytest import numpy as np from numpy.testing import IS_MUSL, assert_, assert_equal, assert_raises +from numpy.testing._private.utils import LONG_DOUBLE_IS_IBM_DOUBLE_DOUBLE class TestRealScalars: @@ -329,8 +329,8 @@ def test_dragon4_scientific_interface(self, tp): assert_equal(fsci(tp('1.0'), unique=False, precision=4), "1.0000e+00") - @pytest.mark.skipif(not platform.machine().startswith("ppc64"), - reason="only applies to ppc float128 values") + @pytest.mark.skipif(not LONG_DOUBLE_IS_IBM_DOUBLE_DOUBLE, + reason="only applies to ppc double-double values") def test_ppc64_ibm_double_double128(self): # check that the precision decreases once we get into the subnormal # range. Unlike float64, this starts around 1e-292 instead of 1e-308, diff --git a/numpy/_core/tests/test_umath.py b/numpy/_core/tests/test_umath.py index b5f621c7927d..821837cd28da 100644 --- a/numpy/_core/tests/test_umath.py +++ b/numpy/_core/tests/test_umath.py @@ -31,7 +31,10 @@ assert_raises, assert_raises_regex, ) -from numpy.testing._private.utils import _glibc_older_than +from numpy.testing._private.utils import ( + LONG_DOUBLE_IS_IBM_DOUBLE_DOUBLE, + _glibc_older_than, +) UFUNCS = [obj for obj in np._core.umath.__dict__.values() if isinstance(obj, np.ufunc)] @@ -4808,7 +4811,7 @@ def test_nextafterf(): @pytest.mark.skipif(np.finfo(np.double) == np.finfo(np.longdouble), reason="long double is same as double") -@pytest.mark.xfail(condition=platform.machine().startswith("ppc64"), +@pytest.mark.xfail(condition=LONG_DOUBLE_IS_IBM_DOUBLE_DOUBLE, reason="IBM double double") def test_nextafterl(): return _test_nextafter(np.longdouble) @@ -4847,7 +4850,7 @@ def test_spacingf(): @pytest.mark.skipif(np.finfo(np.double) == np.finfo(np.longdouble), reason="long double is same as double") -@pytest.mark.xfail(condition=platform.machine().startswith("ppc64"), +@pytest.mark.xfail(condition=LONG_DOUBLE_IS_IBM_DOUBLE_DOUBLE, reason="IBM double double") def test_spacingl(): return _test_spacing(np.longdouble) diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py index 4cd56cfc4fc4..43eb6a6dd85e 100644 --- a/numpy/testing/_private/utils.py +++ b/numpy/testing/_private/utils.py @@ -107,6 +107,10 @@ class KnownFailureException(Exception): NOGIL_BUILD = bool(sysconfig.get_config_var("Py_GIL_DISABLED")) IS_64BIT = np.dtype(np.intp).itemsize == 8 +LONG_DOUBLE_IS_IBM_DOUBLE_DOUBLE = (platform.machine().startswith("ppc") + and str(np.finfo(np.longdouble).max) + == "1.79769313486231580793728971405301e+308") + def assert_(val, msg=''): """ Assert that works in release mode.