summaryrefslogtreecommitdiff
path: root/numpy/core/numeric.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r--numpy/core/numeric.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py
index 60111e1f2..e4693431c 100644
--- a/numpy/core/numeric.py
+++ b/numpy/core/numeric.py
@@ -2086,19 +2086,24 @@ def isclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False):
if isscalar(a) and isscalar(b):
result = bool(result)
return result
- x = array(a, copy=False, ndmin=1)
- y = array(b, copy=False, ndmin=1)
+ x = array(a, copy=False, subok=True, ndmin=1)
+ y = array(b, copy=False, subok=True, ndmin=1)
xfin = isfinite(x)
yfin = isfinite(y)
if all(xfin) and all(yfin):
return within_tol(x, y, atol, rtol)
else:
+ finite = xfin & yfin
+ # Because we're using boolean indexing, x & y must be the same shape.
+ # Ideally, we'd just do x, y = broadcast_arrays(x, y). It's in
+ # lib.stride_tricks, though, so we can't import it here.
+ cond = zeros_like(finite, subok=True)
+ x = x * ones_like(cond)
+ y = y * ones_like(cond)
# Avoid subtraction with infinite/nan values...
- cond = zeros(broadcast(x, y).shape, dtype=bool)
- mask = xfin & yfin
- cond[mask] = within_tol(x[mask], y[mask], atol, rtol)
+ cond[finite] = within_tol(x[finite], y[finite], atol, rtol)
# Check for equality of infinite values...
- cond[~mask] = (x[~mask] == y[~mask])
+ cond[~finite] = (x[~finite] == y[~finite])
if equal_nan:
# Make NaN == NaN
cond[isnan(x) & isnan(y)] = True