summaryrefslogtreecommitdiff
path: root/numpy/testing/_private/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/testing/_private/utils.py')
-rw-r--r--numpy/testing/_private/utils.py42
1 files changed, 33 insertions, 9 deletions
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py
index 8b098f1d1..4097a6738 100644
--- a/numpy/testing/_private/utils.py
+++ b/numpy/testing/_private/utils.py
@@ -284,7 +284,7 @@ def assert_equal(actual, desired, err_msg='', verbose=True):
the scalar.
This function handles NaN comparisons as if NaN was a "normal" number.
- That is, no assertion is raised if both objects have NaNs in the same
+ That is, AssertionError is not raised if both objects have NaNs in the same
positions. This is in contrast to the IEEE standard on NaNs, which says
that NaN compared to anything must return False.
@@ -530,7 +530,8 @@ def assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=True):
...
AssertionError:
Arrays are not almost equal to 9 decimals
- Mismatch: 50%
+ <BLANKLINE>
+ Mismatched elements: 1 / 2 (50%)
Max absolute difference: 6.66669964e-09
Max relative difference: 2.85715698e-09
x: array([1. , 2.333333333])
@@ -904,7 +905,8 @@ def assert_array_equal(x, y, err_msg='', verbose=True):
...
AssertionError:
Arrays are not equal
- Mismatch: 33.3%
+ <BLANKLINE>
+ Mismatched elements: 1 / 3 (33.3%)
Max absolute difference: 4.4408921e-16
Max relative difference: 1.41357986e-16
x: array([1. , 3.141593, nan])
@@ -987,7 +989,8 @@ def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True):
...
AssertionError:
Arrays are not almost equal to 5 decimals
- Mismatch: 33.3%
+ <BLANKLINE>
+ Mismatched elements: 1 / 3 (33.3%)
Max absolute difference: 6.e-05
Max relative difference: 2.57136612e-05
x: array([1. , 2.33333, nan])
@@ -999,6 +1002,7 @@ def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True):
...
AssertionError:
Arrays are not almost equal to 5 decimals
+ <BLANKLINE>
x and y nan location mismatch:
x: array([1. , 2.33333, nan])
y: array([1. , 2.33333, 5. ])
@@ -1086,7 +1090,8 @@ def assert_array_less(x, y, err_msg='', verbose=True):
...
AssertionError:
Arrays are not less-ordered
- Mismatch: 33.3%
+ <BLANKLINE>
+ Mismatched elements: 1 / 3 (33.3%)
Max absolute difference: 1.
Max relative difference: 0.5
x: array([ 1., 1., nan])
@@ -1097,7 +1102,8 @@ def assert_array_less(x, y, err_msg='', verbose=True):
...
AssertionError:
Arrays are not less-ordered
- Mismatch: 50%
+ <BLANKLINE>
+ Mismatched elements: 1 / 2 (50%)
Max absolute difference: 2.
Max relative difference: 0.66666667
x: array([1., 4.])
@@ -1108,6 +1114,7 @@ def assert_array_less(x, y, err_msg='', verbose=True):
...
AssertionError:
Arrays are not less-ordered
+ <BLANKLINE>
(shapes (3,), (1,) mismatch)
x: array([1., 2., 3.])
y: array([4])
@@ -1444,7 +1451,9 @@ def _assert_valid_refcount(op):
"""
if not HAS_REFCOUNT:
return True
- import numpy as np, gc
+
+ import gc
+ import numpy as np
b = np.arange(100*100).reshape(100, 100)
c = b
@@ -1607,6 +1616,12 @@ def assert_array_max_ulp(a, b, maxulp=1, dtype=None):
AssertionError
If one or more elements differ by more than `maxulp`.
+ Notes
+ -----
+ For computing the ULP difference, this API does not differentiate between
+ various representations of NAN (ULP difference between 0x7fc00000 and 0xffc00000
+ is zero).
+
See Also
--------
assert_array_almost_equal_nulp : Compare two arrays relatively to their
@@ -1647,6 +1662,12 @@ def nulp_diff(x, y, dtype=None):
number of representable floating point numbers between each item in x
and y.
+ Notes
+ -----
+ For computing the ULP difference, this API does not differentiate between
+ various representations of NAN (ULP difference between 0x7fc00000 and 0xffc00000
+ is zero).
+
Examples
--------
# By definition, epsilon is the smallest number such as 1 + eps != 1, so
@@ -1666,8 +1687,11 @@ def nulp_diff(x, y, dtype=None):
if np.iscomplexobj(x) or np.iscomplexobj(y):
raise NotImplementedError("_nulp not implemented for complex array")
- x = np.array(x, dtype=t)
- y = np.array(y, dtype=t)
+ x = np.array([x], dtype=t)
+ y = np.array([y], dtype=t)
+
+ x[np.isnan(x)] = np.nan
+ y[np.isnan(y)] = np.nan
if not x.shape == y.shape:
raise ValueError("x and y do not have the same shape: %s - %s" %