From baaeb9a16c9c28683db97c4fc3d047e86d32a0c5 Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Thu, 26 May 2022 20:48:02 -0700 Subject: WIP: Add warning context manager and fix min_scalar for new promotion Even the new promotion has to use the min-scalar logic to avoid picking up a float16 loop for `np.int8(3) * 3.`. --- numpy/testing/_private/utils.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'numpy/testing/_private/utils.py') diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py index e4f8b9892..ca64446db 100644 --- a/numpy/testing/_private/utils.py +++ b/numpy/testing/_private/utils.py @@ -473,6 +473,7 @@ def print_assert_equal(test_string, actual, desired): raise AssertionError(msg.getvalue()) +@np.no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired @@ -599,6 +600,7 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): raise AssertionError(_build_err_msg()) +@np.no_nep50_warning() def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to significant @@ -698,6 +700,7 @@ def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True): raise AssertionError(msg) +@np.no_nep50_warning() def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True): __tracebackhide__ = True # Hide traceback for py.test @@ -935,6 +938,7 @@ def assert_array_equal(x, y, err_msg='', verbose=True): verbose=verbose, header='Arrays are not equal') +@np.no_nep50_warning() def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): """ Raises an AssertionError if two objects are not equal up to desired -- cgit v1.2.1 From ffab4c45b3ad5264ff137b9f08490b6c986f9763 Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Fri, 27 May 2022 15:11:49 -0700 Subject: TST: Make test compatible with new promotion or mark for no-warnings --- numpy/testing/_private/utils.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'numpy/testing/_private/utils.py') 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. -- cgit v1.2.1 From 80af7aceb1af9e35ed67abce66beab46ddd2bfa6 Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Sat, 28 May 2022 11:27:37 -0700 Subject: API: Enforce float64 precision for `assert_almost_equal` This ensures that the precision is not downcast, which could make a small value zero (for float16 mostly). This lets tests pass that check whether `np.float16(0)` is almost equal to 0, which otherwise fail (because `float16(0.00000001)` will evaluate to 0 exactly. --- numpy/testing/_private/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'numpy/testing/_private/utils.py') diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py index a4e80b026..73ff88737 100644 --- a/numpy/testing/_private/utils.py +++ b/numpy/testing/_private/utils.py @@ -489,7 +489,7 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): The test verifies that the elements of `actual` and `desired` satisfy. - ``abs(desired-actual) < 1.5 * 10**(-decimal)`` + ``abs(desired-actual) < float64(1.5 * 10**(-decimal))`` That is a looser test than originally documented, but agrees with what the actual implementation in `assert_array_almost_equal` did up to rounding @@ -599,7 +599,7 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): return except (NotImplementedError, TypeError): pass - if abs(desired - actual) >= 1.5 * 10.0**(-decimal): + if abs(desired - actual) >= np.float64(1.5 * 10.0**(-decimal)): raise AssertionError(_build_err_msg()) -- cgit v1.2.1 From 974c865219223742a07375bea1f6da246e3326ef Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Wed, 8 Jun 2022 16:35:31 -0700 Subject: API: Add leading underscore to `no_nep50_warning` and `get/set_promotion_state` --- numpy/testing/_private/utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'numpy/testing/_private/utils.py') diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py index 73ff88737..4ec42cbb8 100644 --- a/numpy/testing/_private/utils.py +++ b/numpy/testing/_private/utils.py @@ -53,7 +53,7 @@ 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' +OLD_PROMOTION = np._get_promotion_state() == 'legacy' def import_nose(): @@ -476,7 +476,7 @@ def print_assert_equal(test_string, actual, desired): raise AssertionError(msg.getvalue()) -@np.no_nep50_warning() +@np._no_nep50_warning() def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to desired @@ -603,7 +603,7 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True): raise AssertionError(_build_err_msg()) -@np.no_nep50_warning() +@np._no_nep50_warning() def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True): """ Raises an AssertionError if two items are not equal up to significant @@ -703,7 +703,7 @@ def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True): raise AssertionError(msg) -@np.no_nep50_warning() +@np._no_nep50_warning() def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True): __tracebackhide__ = True # Hide traceback for py.test @@ -941,7 +941,7 @@ def assert_array_equal(x, y, err_msg='', verbose=True): verbose=verbose, header='Arrays are not equal') -@np.no_nep50_warning() +@np._no_nep50_warning() def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True): """ Raises an AssertionError if two objects are not equal up to desired -- cgit v1.2.1 From c6597ac89f3690a44df27fb71885fc1490e82be5 Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Thu, 9 Jun 2022 11:15:04 -0700 Subject: TST: Improve testing setup by introducing a new `weak_promotion` fixture Unfortunately, this shows that the rational tests are still broken a bit. --- numpy/testing/_private/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'numpy/testing/_private/utils.py') diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py index 4ec42cbb8..d7e218486 100644 --- a/numpy/testing/_private/utils.py +++ b/numpy/testing/_private/utils.py @@ -36,7 +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' + '_OLD_PROMOTION' ] @@ -53,7 +53,7 @@ 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' +_OLD_PROMOTION = lambda: np._get_promotion_state() == 'legacy' def import_nose(): -- cgit v1.2.1