diff options
author | Patrick Peglar <patrick.peglar@metoffice.gov.uk> | 2014-08-31 15:43:39 +0100 |
---|---|---|
committer | Patrick Peglar <patrick.peglar@metoffice.gov.uk> | 2014-08-31 15:43:39 +0100 |
commit | 4097ec3ec10c41d399518867f4bebb0a53ee8a5c (patch) | |
tree | 0e4662c49fb39113c82965588f7d3128bb8fa982 /numpy/core/numeric.py | |
parent | 9c50f988ac27dd1758dbc46455573aaa77638c68 (diff) | |
download | numpy-4097ec3ec10c41d399518867f4bebb0a53ee8a5c.tar.gz |
BUG: fix percentage reporting when testing.assert_allclose fails.
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r-- | numpy/core/numeric.py | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index efd8af45d..eb0c38b0b 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -2153,6 +2153,41 @@ def identity(n, dtype=None): from numpy import eye return eye(n, dtype=dtype) +def _allclose_points(a, b, rtol=1.e-5, atol=1.e-8): + """ + This is the point-wise inner calculation of 'allclose', which is subtly + different from 'isclose'. Provided as a comparison routine for use in + testing.assert_allclose. + See those routines for further details. + + """ + x = array(a, copy=False, ndmin=1) + y = array(b, copy=False, ndmin=1) + + # make sure y is an inexact type to avoid abs(MIN_INT); will cause + # casting of x later. + dtype = multiarray.result_type(y, 1.) + y = array(y, dtype=dtype, copy=False) + + xinf = isinf(x) + yinf = isinf(y) + if any(xinf) or any(yinf): + # Check that x and y have inf's only in the same positions + if not all(xinf == yinf): + return False + # Check that sign of inf's in x and y is the same + if not all(x[xinf] == y[xinf]): + return False + + x = x[~xinf] + y = y[~xinf] + + # ignore invalid fpe's + with errstate(invalid='ignore'): + r = less_equal(abs(x - y), atol + rtol * abs(y)) + + return r + def allclose(a, b, rtol=1.e-5, atol=1.e-8): """ Returns True if two arrays are element-wise equal within a tolerance. @@ -2208,32 +2243,7 @@ def allclose(a, b, rtol=1.e-5, atol=1.e-8): False """ - x = array(a, copy=False, ndmin=1) - y = array(b, copy=False, ndmin=1) - - # make sure y is an inexact type to avoid abs(MIN_INT); will cause - # casting of x later. - dtype = multiarray.result_type(y, 1.) - y = array(y, dtype=dtype, copy=False) - - xinf = isinf(x) - yinf = isinf(y) - if any(xinf) or any(yinf): - # Check that x and y have inf's only in the same positions - if not all(xinf == yinf): - return False - # Check that sign of inf's in x and y is the same - if not all(x[xinf] == y[xinf]): - return False - - x = x[~xinf] - y = y[~xinf] - - # ignore invalid fpe's - with errstate(invalid='ignore'): - r = all(less_equal(abs(x - y), atol + rtol * abs(y))) - - return r + return all(_allclose_points(a, b, rtol=rtol, atol=atol)) def isclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False): """ |