diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2014-02-12 11:57:27 +0100 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2014-02-16 00:00:22 +0100 |
commit | ab04e1ae0e8eca717bc7e42f3b0a60c9ff764289 (patch) | |
tree | 49ea02f820c4ee3eb484578abd0078f543ef4898 /numpy/core/numeric.py | |
parent | 58e9e27c0c110f9be1558a53fb547dc1abc76fa4 (diff) | |
download | numpy-ab04e1ae0e8eca717bc7e42f3b0a60c9ff764289.tar.gz |
BUG: Force allclose logic to use inexact type
Casting y to an inexact type fixes problems such as
abs(MIN_INT) < 0, and generally makes sense since the allclose
logic is inherently for float types.
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r-- | numpy/core/numeric.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 6b078ae31..3b8e52e71 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -2139,6 +2139,11 @@ def allclose(a, b, rtol=1.e-5, atol=1.e-8): 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): @@ -2154,12 +2159,7 @@ def allclose(a, b, rtol=1.e-5, atol=1.e-8): # ignore invalid fpe's with errstate(invalid='ignore'): - if not x.dtype.kind == 'b' and not y.dtype.kind == 'b': - diff = abs(x - y) - else: - diff = x ^ y - - r = all(less_equal(diff, atol + rtol * abs(y))) + r = all(less_equal(abs(x - y), atol + rtol * abs(y))) return r |