diff options
Diffstat (limited to 'numpy/ma')
-rw-r--r-- | numpy/ma/core.py | 10 | ||||
-rw-r--r-- | numpy/ma/extras.py | 4 | ||||
-rw-r--r-- | numpy/ma/tests/test_core.py | 4 |
3 files changed, 16 insertions, 2 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py index e4116fbd8..e1ae02331 100644 --- a/numpy/ma/core.py +++ b/numpy/ma/core.py @@ -6926,6 +6926,13 @@ def allclose (a, b, masked_equal=True, rtol=1e-5, atol=1e-8): """ x = masked_array(a, copy=False) y = masked_array(b, copy=False) + + # make sure y is an inexact type to avoid abs(MIN_INT); will cause + # casting of x later. + dtype = np.result_type(y, 1.) + if y.dtype != dtype: + y = masked_array(y, dtype=dtype, copy=False) + m = mask_or(getmask(x), getmask(y)) xinf = np.isinf(masked_array(x, copy=False, mask=m)).filled(False) # If we have some infs, they should fall at the same place. @@ -6937,13 +6944,16 @@ def allclose (a, b, masked_equal=True, rtol=1e-5, atol=1e-8): atol + rtol * umath.absolute(y)), masked_equal) return np.all(d) + if not np.all(filled(x[xinf] == y[xinf], masked_equal)): return False x = x[~xinf] y = y[~xinf] + d = filled(umath.less_equal(umath.absolute(x - y), atol + rtol * umath.absolute(y)), masked_equal) + return np.all(d) #.............................................................................. diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index 058bde710..c2d105584 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -540,7 +540,7 @@ def average(a, axis=None, weights=None, returned=False): else: if weights is None: n = add.reduce(a, axis) - d = umath.add.reduce((-mask), axis=axis, dtype=float) + d = umath.add.reduce((~mask), axis=axis, dtype=float) else: w = filled(weights, 0.0) wsh = w.shape @@ -1735,7 +1735,7 @@ def _ezclump(mask): #def clump_masked(a): if mask.ndim > 1: mask = mask.ravel() - idx = (mask[1:] - mask[:-1]).nonzero() + idx = (mask[1:] ^ mask[:-1]).nonzero() idx = idx[0] + 1 slices = [slice(left, right) for (left, right) in zip(itertools.chain([0], idx), diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 8d8e1c947..19f13a8c4 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -1995,6 +1995,10 @@ class TestMaskedArrayMethods(TestCase): a[0] = 0 self.assertTrue(allclose(a, 0, masked_equal=True)) + # Test that the function works for MIN_INT integer typed arrays + a = masked_array([np.iinfo(np.int_).min], dtype=np.int_) + self.assertTrue(allclose(a, a)) + def test_allany(self): # Checks the any/all methods/functions. x = np.array([[0.13, 0.26, 0.90], |