[Numpy-svn] r3596 - in trunk/numpy/core: . tests

numpy-svn@scip... numpy-svn@scip...
Sat Mar 24 18:46:05 CDT 2007


Author: charris
Date: 2007-03-24 18:46:03 -0500 (Sat, 24 Mar 2007)
New Revision: 3596

Modified:
   trunk/numpy/core/defmatrix.py
   trunk/numpy/core/tests/test_regression.py
Log:
Fix matrix-scalar multiplication. Add test for case Matrix*1d-vector

Modified: trunk/numpy/core/defmatrix.py
===================================================================
--- trunk/numpy/core/defmatrix.py	2007-03-24 23:14:07 UTC (rev 3595)
+++ trunk/numpy/core/defmatrix.py	2007-03-24 23:46:03 UTC (rev 3596)
@@ -154,12 +154,12 @@
 
 
     def __mul__(self, other):
-        try :
-            rhs = asmatrix(other)
-        except :
-            return NotImplemented
-        else :
-            return N.dot(self, rhs)
+        if not isscalar(other) :
+            try :
+                other = asmatrix(other)
+            except :
+                return NotImplemented
+        return N.dot(self, other)
 
     def __rmul__(self, other):
         return N.dot(other, self)

Modified: trunk/numpy/core/tests/test_regression.py
===================================================================
--- trunk/numpy/core/tests/test_regression.py	2007-03-24 23:14:07 UTC (rev 3595)
+++ trunk/numpy/core/tests/test_regression.py	2007-03-24 23:46:03 UTC (rev 3596)
@@ -633,5 +633,12 @@
         assert_equal(N.array("a\x00\x0b\x0c\x00").item(),
                      'a\x00\x0b\x0c')
 
+    def check_matrix_multiply_by_1d_vector(self, level=rlevel) :
+        """Ticket #473"""
+        def mul() :
+            N.mat(N.eye(2))*N.ones(2)
+
+        self.failUnlessRaises(ValueError,mul)
+
 if __name__ == "__main__":
     NumpyTest().run()



More information about the Numpy-svn mailing list