diff options
| -rw-r--r-- | numpy/core/tests/test_dtype.py | 17 | ||||
| -rw-r--r-- | numpy/core/tests/test_einsum.py | 1 | ||||
| -rw-r--r-- | numpy/core/tests/test_half.py | 40 | ||||
| -rw-r--r-- | numpy/testing/_private/utils.py | 3 |
4 files changed, 37 insertions, 24 deletions
diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index b37bded73..133a3e29b 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -11,7 +11,7 @@ from numpy.core._rational_tests import rational from numpy.core._multiarray_tests import create_custom_field_dtype from numpy.testing import ( assert_, assert_equal, assert_array_equal, assert_raises, HAS_REFCOUNT, - IS_PYSTON) + IS_PYSTON, OLD_PROMOTION) from numpy.compat import pickle from itertools import permutations import random @@ -1288,21 +1288,26 @@ class TestPromotion: """Test cases related to more complex DType promotions. Further promotion tests are defined in `test_numeric.py` """ + @np.no_nep50_warning() @pytest.mark.parametrize(["other", "expected"], [(2**16-1, np.complex64), - (2**32-1, np.complex128), + (2**32-1, np.complex128 if OLD_PROMOTION else np.complex64), (np.float16(2), np.complex64), (np.float32(2), np.complex64), - (np.longdouble(2), np.complex64), + (np.longdouble(2), + np.complex64 if OLD_PROMOTION else np.clongdouble), # Base of the double value to sidestep any rounding issues: - (np.longdouble(np.nextafter(1.7e308, 0.)), np.complex128), + (np.longdouble(np.nextafter(1.7e308, 0.)), + np.complex128 if OLD_PROMOTION else np.clongdouble), # Additionally use "nextafter" so the cast can't round down: (np.longdouble(np.nextafter(1.7e308, np.inf)), np.clongdouble), # repeat for complex scalars: (np.complex64(2), np.complex64), - (np.clongdouble(2), np.complex64), + (np.clongdouble(2), + np.complex64 if OLD_PROMOTION else np.clongdouble), # Base of the double value to sidestep any rounding issues: - (np.clongdouble(np.nextafter(1.7e308, 0.) * 1j), np.complex128), + (np.clongdouble(np.nextafter(1.7e308, 0.) * 1j), + np.complex128 if OLD_PROMOTION else np.clongdouble), # Additionally use "nextafter" so the cast can't round down: (np.clongdouble(np.nextafter(1.7e308, np.inf)), np.clongdouble), ]) diff --git a/numpy/core/tests/test_einsum.py b/numpy/core/tests/test_einsum.py index 0ef1b714b..05ef124d0 100644 --- a/numpy/core/tests/test_einsum.py +++ b/numpy/core/tests/test_einsum.py @@ -239,6 +239,7 @@ class TestEinsum: assert_(b.base is a) assert_equal(b, a.swapaxes(0, 1)) + @np.no_nep50_warning() def check_einsum_sums(self, dtype, do_opt=False): # Check various sums. Does many sizes to exercise unrolled loops. diff --git a/numpy/core/tests/test_half.py b/numpy/core/tests/test_half.py index 6743dfb51..562dc0591 100644 --- a/numpy/core/tests/test_half.py +++ b/numpy/core/tests/test_half.py @@ -85,6 +85,7 @@ class TestHalf: @pytest.mark.parametrize("offset", [None, "up", "down"]) @pytest.mark.parametrize("shift", [None, "up", "down"]) @pytest.mark.parametrize("float_t", [np.float32, np.float64]) + @np.no_nep50_warning() def test_half_conversion_rounding(self, float_t, shift, offset): # Assumes that round to even is used during casting. max_pattern = np.float16(np.finfo(np.float16).max).view(np.uint16) @@ -457,24 +458,27 @@ class TestHalf: b16 = float16(1) b32 = float32(1) - assert_equal(np.power(a16, 2).dtype, float16) - assert_equal(np.power(a16, 2.0).dtype, float16) - assert_equal(np.power(a16, b16).dtype, float16) - assert_equal(np.power(a16, b32).dtype, float16) - assert_equal(np.power(a16, a16).dtype, float16) - assert_equal(np.power(a16, a32).dtype, float32) - - assert_equal(np.power(b16, 2).dtype, float64) - assert_equal(np.power(b16, 2.0).dtype, float64) - assert_equal(np.power(b16, b16).dtype, float16) - assert_equal(np.power(b16, b32).dtype, float32) - assert_equal(np.power(b16, a16).dtype, float16) - assert_equal(np.power(b16, a32).dtype, float32) - - assert_equal(np.power(a32, a16).dtype, float32) - assert_equal(np.power(a32, b16).dtype, float32) - assert_equal(np.power(b32, a16).dtype, float16) - assert_equal(np.power(b32, b16).dtype, float32) + assert np.power(a16, 2).dtype == float16 + assert np.power(a16, 2.0).dtype == float16 + assert np.power(a16, b16).dtype == float16 + expected_dt = float16 if OLD_PROMOTION else float32 + assert np.power(a16, b32).dtype == expected_dt + assert np.power(a16, a16).dtype == float16 + assert np.power(a16, a32).dtype == float32 + + expected_dt = float64 if OLD_PROMOTION else float16 + assert np.power(b16, 2).dtype == expected_dt + assert np.power(b16, 2.0).dtype == expected_dt + assert np.power(b16, b16).dtype, float16 + assert np.power(b16, b32).dtype, float32 + assert np.power(b16, a16).dtype, float16 + assert np.power(b16, a32).dtype, float32 + + assert np.power(a32, a16).dtype == float32 + assert np.power(a32, b16).dtype == float32 + expected_dt = float16 if OLD_PROMOTION else float32 + assert np.power(b32, a16).dtype == expected_dt + assert np.power(b32, b16).dtype == float32 @pytest.mark.skipif(platform.machine() == "armv5tel", reason="See gh-413.") diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py index ca64446db..a4e80b026 100644 --- a/numpy/testing/_private/utils.py +++ b/numpy/testing/_private/utils.py @@ -36,6 +36,7 @@ __all__ = [ 'SkipTest', 'KnownFailureException', 'temppath', 'tempdir', 'IS_PYPY', 'HAS_REFCOUNT', 'suppress_warnings', 'assert_array_compare', 'assert_no_gc_cycles', 'break_cycles', 'HAS_LAPACK64', 'IS_PYSTON', + 'OLD_PROMOTION' ] @@ -52,6 +53,8 @@ IS_PYSTON = hasattr(sys, "pyston_version_info") HAS_REFCOUNT = getattr(sys, 'getrefcount', None) is not None and not IS_PYSTON HAS_LAPACK64 = numpy.linalg.lapack_lite._ilp64 +OLD_PROMOTION = np.get_promotion_state() == 'legacy' + def import_nose(): """ Import nose only when needed. |
