From ab04e1ae0e8eca717bc7e42f3b0a60c9ff764289 Mon Sep 17 00:00:00 2001 From: Sebastian Berg Date: Wed, 12 Feb 2014 11:57:27 +0100 Subject: 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. --- numpy/core/numeric.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'numpy/core/numeric.py') 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 -- cgit v1.2.1