[Numpy-svn] r5507 - in branches/1.1.x/numpy/ma: . tests

numpy-svn@scip... numpy-svn@scip...
Tue Jul 22 15:56:49 CDT 2008


Author: pierregm
Date: 2008-07-22 15:56:27 -0500 (Tue, 22 Jul 2008)
New Revision: 5507

Modified:
   branches/1.1.x/numpy/ma/core.py
   branches/1.1.x/numpy/ma/tests/test_core.py
Log:
* force the domain to the shape of the other element in DomainedBinaryOperation (bugfix 857)

Modified: branches/1.1.x/numpy/ma/core.py
===================================================================
--- branches/1.1.x/numpy/ma/core.py	2008-07-22 20:52:48 UTC (rev 5506)
+++ branches/1.1.x/numpy/ma/core.py	2008-07-22 20:56:27 UTC (rev 5507)
@@ -626,7 +626,10 @@
         if t.any(None):
             mb = mask_or(mb, t)
             # The following line controls the domain filling
-            d2 = np.where(t,self.filly,d2)
+            if t.size == d2.size:
+                d2 = np.where(t,self.filly,d2)
+            else:
+                d2 = np.where(np.resize(t, d2.shape),self.filly, d2)
         m = mask_or(ma, mb)
         if (not m.ndim) and m:
             return masked

Modified: branches/1.1.x/numpy/ma/tests/test_core.py
===================================================================
--- branches/1.1.x/numpy/ma/tests/test_core.py	2008-07-22 20:52:48 UTC (rev 5506)
+++ branches/1.1.x/numpy/ma/tests/test_core.py	2008-07-22 20:56:27 UTC (rev 5507)
@@ -1609,7 +1609,26 @@
         assert_almost_equal(x._data,y._data)
 
 
+    def test_divide_on_different_shapes(self):
+        x = arange(6, dtype=float)
+        x.shape = (2,3)
+        y = arange(3, dtype=float)
+        #
+        z = x/y
+        assert_equal(z, [[-1.,1.,1.], [-1.,4.,2.5]])
+        assert_equal(z.mask, [[1,0,0],[1,0,0]])
+        #
+        z = x/y[None,:]
+        assert_equal(z, [[-1.,1.,1.], [-1.,4.,2.5]])
+        assert_equal(z.mask, [[1,0,0],[1,0,0]])
+        #
+        y = arange(2, dtype=float)
+        z = x/y[:,None]
+        assert_equal(z, [[-1.,-1.,-1.], [3.,4.,5.]])
+        assert_equal(z.mask, [[1,1,1],[0,0,0]])
 
+
+
 ###############################################################################
 #------------------------------------------------------------------------------
 if __name__ == "__main__":



More information about the Numpy-svn mailing list