summaryrefslogtreecommitdiff
path: root/numpy/testing/_private/utils.py
diff options
context:
space:
mode:
authorRaghuveer Devulapalli <raghuveer.devulapalli@intel.com>2020-02-18 11:42:08 -0800
committerRaghuveer Devulapalli <raghuveer.devulapalli@intel.com>2020-02-18 13:24:57 -0800
commit8f25b48688e748d8269efd52c69cc7fcf68f4b23 (patch)
treed4abf989ccae95e203123444e8e44b48bbba82a4 /numpy/testing/_private/utils.py
parent4d2b5850488013319ff8354a1e764a0a2064fe63 (diff)
downloadnumpy-8f25b48688e748d8269efd52c69cc7fcf68f4b23.tar.gz
BUG: Ignore differences in NAN representation for computing ULP differences
Diffstat (limited to 'numpy/testing/_private/utils.py')
-rw-r--r--numpy/testing/_private/utils.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py
index 67b7d317c..bf0892a29 100644
--- a/numpy/testing/_private/utils.py
+++ b/numpy/testing/_private/utils.py
@@ -1609,6 +1609,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
@@ -1649,6 +1655,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
@@ -1668,8 +1680,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" %