summaryrefslogtreecommitdiff
path: root/numpy/testing/_private/utils.py
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2022-05-28 11:27:37 -0700
committerSebastian Berg <sebastian@sipsolutions.net>2022-06-15 11:42:02 -0700
commit80af7aceb1af9e35ed67abce66beab46ddd2bfa6 (patch)
treecf93e45446c3f4db0c9fc8a66ad138253e45e6d3 /numpy/testing/_private/utils.py
parentb2731a5ec4f765205d5c797299e8a4ba1e4b04ca (diff)
downloadnumpy-80af7aceb1af9e35ed67abce66beab46ddd2bfa6.tar.gz
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.
Diffstat (limited to 'numpy/testing/_private/utils.py')
-rw-r--r--numpy/testing/_private/utils.py4
1 files changed, 2 insertions, 2 deletions
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())