diff options
author | pierregm <pierregm@localhost> | 2009-01-27 02:46:26 +0000 |
---|---|---|
committer | pierregm <pierregm@localhost> | 2009-01-27 02:46:26 +0000 |
commit | f885786515b1e3cf5f293ca508c08a9f782f5076 (patch) | |
tree | 2c573cfab58d5d93d4bbe7d6af4dd8106ad0b194 /numpy/ma/tests | |
parent | 2e346ec1e1000c11f484708e2997b7b95808a00d (diff) | |
download | numpy-f885786515b1e3cf5f293ca508c08a9f782f5076.tar.gz |
* prevent MaskedBinaryOperation and DomainedBinaryOperation to shrink the mask of the output when at least one of the inputs has a mask full of False
Diffstat (limited to 'numpy/ma/tests')
-rw-r--r-- | numpy/ma/tests/test_core.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py index 090613f7e..9c523429a 100644 --- a/numpy/ma/tests/test_core.py +++ b/numpy/ma/tests/test_core.py @@ -869,6 +869,60 @@ class TestMaskedArrayArithmetic(TestCase): assert_equal(test.mask, control.mask) + def test_domained_binops_d2D(self): + "Test domained binary operations on 2D data" + a = array([[1.], [2.], [3.]], mask=[[False], [True], [True]]) + b = array([[2., 3.], [4., 5.], [6., 7.]]) + # + test = a / b + control = array([[1./2., 1./3.], [2., 2.], [3., 3.]], + mask=[[0, 0], [1, 1], [1, 1]]) + assert_equal(test, control) + assert_equal(test.data, control.data) + assert_equal(test.mask, control.mask) + # + test = b / a + control = array([[2./1., 3./1.], [4., 5.], [6., 7.]], + mask=[[0, 0], [1, 1], [1, 1]]) + assert_equal(test, control) + assert_equal(test.data, control.data) + assert_equal(test.mask, control.mask) + # + a = array([[1.], [2.], [3.]]) + b = array([[2., 3.], [4., 5.], [6., 7.]], + mask=[[0, 0], [0, 0], [0, 1]]) + test = a / b + control = array([[1./2, 1./3], [2./4, 2./5], [3./6, 3]], + mask=[[0, 0], [0, 0], [0, 1]]) + assert_equal(test, control) + assert_equal(test.data, control.data) + assert_equal(test.mask, control.mask) + # + test = b / a + control = array([[2/1., 3/1.], [4/2., 5/2.], [6/3., 7]], + mask=[[0, 0], [0, 0], [0, 1]]) + assert_equal(test, control) + assert_equal(test.data, control.data) + assert_equal(test.mask, control.mask) + + + def test_noshrinking(self): + "Check that we don't shrink a mask when not wanted" + # Binary operations + a = masked_array([1,2,3], mask=[False,False,False], shrink=False) + b = a + 1 + assert_equal(b.mask, [0, 0, 0]) + # In place binary operation + a += 1 + assert_equal(a.mask, [0, 0, 0]) + # Domained binary operation + b = a / 1. + assert_equal(b.mask, [0, 0, 0]) + # In place binary operation + a /= 1. + assert_equal(a.mask, [0, 0, 0]) + + def test_mod(self): "Tests mod" (x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d |