summaryrefslogtreecommitdiff
path: root/numpy/testing/utils.py
diff options
context:
space:
mode:
authorDavid Cournapeau <cournape@gmail.com>2009-10-30 10:27:37 +0000
committerDavid Cournapeau <cournape@gmail.com>2009-10-30 10:27:37 +0000
commitb325f7350facb82a1fc72b4a52e61d90a0101962 (patch)
tree478e177b1de68d3f54783eb44798c8a64782007f /numpy/testing/utils.py
parentfd1990d6425345f9b3827d91d9020e1047968a12 (diff)
downloadnumpy-b325f7350facb82a1fc72b4a52e61d90a0101962.tar.gz
ENH: add assert_array_max_ulp comparison function.
This new comparison raises an error if the number of representable numbers between two arrays exceeds a tolerance.
Diffstat (limited to 'numpy/testing/utils.py')
-rw-r--r--numpy/testing/utils.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py
index 3e789272e..c5be4c49d 100644
--- a/numpy/testing/utils.py
+++ b/numpy/testing/utils.py
@@ -14,7 +14,8 @@ __all__ = ['assert_equal', 'assert_almost_equal','assert_approx_equal',
'assert_array_almost_equal', 'assert_raises', 'build_err_msg',
'decorate_methods', 'jiffies', 'memusage', 'print_assert_equal',
'raises', 'rand', 'rundocs', 'runstring', 'verbose', 'measure',
- 'assert_', 'spacing', 'assert_array_almost_equal_nulp']
+ 'assert_', 'spacing', 'assert_array_almost_equal_nulp',
+ 'assert_array_max_ulp']
verbose = 0
@@ -1110,6 +1111,16 @@ def assert_array_almost_equal_nulp(x, y, nulp=1):
raise AssertionError("X and Y are not equal to %d ULP "\
"(max is %d)" % (nulp, max_nulp))
+def assert_array_max_ulp(a, b, maxulp=1, dtype=None):
+ """Given two arrays a and b, check that every item differs in at most N
+ Unit in the Last Place."""
+ import numpy as np
+ ret = nulp_diff(a, b, dtype)
+ if not np.all(ret <= maxulp):
+ raise AssertionError("Arrays are not almost equal up to %d ULP" % \
+ maxulp)
+ return ret
+
def nulp_diff(x, y, dtype=None):
"""For each item in x and y, eeturn the number of representable floating
points between them.