summaryrefslogtreecommitdiff
path: root/numpy/core/numeric.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2017-09-20 14:26:30 -0500
committerGitHub <noreply@github.com>2017-09-20 14:26:30 -0500
commit41806abf15c442747b2ac66feb4246eb810ff96e (patch)
tree3c7ae03c1c5d25262a19fa4a02e9589427d5e8d4 /numpy/core/numeric.py
parent76cabbbf3b985631212cba6b164c4bac3d2d42c2 (diff)
parent4031845251f6fd59da8840698bf36f4c7e974818 (diff)
downloadnumpy-41806abf15c442747b2ac66feb4246eb810ff96e.tar.gz
Merge pull request #9720 from eric-wieser/simplify-isclose
MAINT: Remove unnecessary special-casing of scalars in isclose
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r--numpy/core/numeric.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py
index fde08490a..c3c34666f 100644
--- a/numpy/core/numeric.py
+++ b/numpy/core/numeric.py
@@ -2528,13 +2528,10 @@ def isclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False):
"""
def within_tol(x, y, atol, rtol):
with errstate(invalid='ignore'):
- result = less_equal(abs(x-y), atol + rtol * abs(y))
- if isscalar(a) and isscalar(b):
- result = bool(result)
- return result
+ return less_equal(abs(x-y), atol + rtol * abs(y))
- x = array(a, copy=False, subok=True, ndmin=1)
- y = array(b, copy=False, subok=True, ndmin=1)
+ x = asanyarray(a)
+ y = asanyarray(b)
# Make sure y is an inexact type to avoid bad behavior on abs(MIN_INT).
# This will cause casting of x later. Also, make sure to allow subclasses
@@ -2561,12 +2558,11 @@ def isclose(a, b, rtol=1.e-5, atol=1.e-8, equal_nan=False):
if equal_nan:
# Make NaN == NaN
both_nan = isnan(x) & isnan(y)
+
+ # Needed to treat masked arrays correctly. = True would not work.
cond[both_nan] = both_nan[both_nan]
- if isscalar(a) and isscalar(b):
- return bool(cond)
- else:
- return cond
+ return cond[()] # Flatten 0d arrays to scalars
def array_equal(a1, a2):