diff options
author | CakeWithSteak <37267737+CakeWithSteak@users.noreply.github.com> | 2019-09-05 16:20:13 +0200 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2019-09-05 09:20:13 -0500 |
commit | 3dccd841476d26b5807156b904b55c04c6a3d370 (patch) | |
tree | 13e25978aad375ff80e3c499e250d43af640b0dc /numpy/testing/_private/utils.py | |
parent | 6bdbc1e2fd20df7272802df88f3790e5dd7ed057 (diff) | |
download | numpy-3dccd841476d26b5807156b904b55c04c6a3d370.tar.gz |
BUG: Fixed maximum relative error reporting in assert_allclose (gh-13802)
Fixed maximum relative error reporting in assert_allclose:
In cases where the two arrays have zeros at the same positions it will
no longer report nan as the max relative error
Diffstat (limited to 'numpy/testing/_private/utils.py')
-rw-r--r-- | numpy/testing/_private/utils.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py index 97a5eac17..4ac0715bf 100644 --- a/numpy/testing/_private/utils.py +++ b/numpy/testing/_private/utils.py @@ -686,7 +686,7 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True, header='', precision=6, equal_nan=True, equal_inf=True): __tracebackhide__ = True # Hide traceback for py.test - from numpy.core import array, array2string, isnan, inf, bool_, errstate + from numpy.core import array, array2string, isnan, inf, bool_, errstate, all x = array(x, copy=False, subok=True) y = array(y, copy=False, subok=True) @@ -807,7 +807,12 @@ def assert_array_compare(comparison, x, y, err_msg='', verbose=True, # note: this definition of relative error matches that one # used by assert_allclose (found in np.isclose) - max_rel_error = (error / abs(y)).max() + # Filter values where the divisor would be zero + nonzero = bool_(y != 0) + if all(~nonzero): + max_rel_error = array(inf) + else: + max_rel_error = (error[nonzero] / abs(y[nonzero])).max() if error.dtype == 'object': remarks.append('Max relative difference: ' + str(max_rel_error)) |