[Scipy-svn] r5294 - in trunk/scipy/sparse: . tests

scipy-svn@scip... scipy-svn@scip...
Sat Dec 27 17:34:17 CST 2008


Author: wnbell
Date: 2008-12-27 17:34:08 -0600 (Sat, 27 Dec 2008)
New Revision: 5294

Modified:
   trunk/scipy/sparse/base.py
   trunk/scipy/sparse/tests/test_base.py
Log:
check for matrix dimensions in sparse * sparse


Modified: trunk/scipy/sparse/base.py
===================================================================
--- trunk/scipy/sparse/base.py	2008-12-27 21:52:58 UTC (rev 5293)
+++ trunk/scipy/sparse/base.py	2008-12-27 23:34:08 UTC (rev 5294)
@@ -283,6 +283,8 @@
             return self._mul_scalar(other)
 
         if issparse(other):
+            if self.shape[1] != other.shape[0]:
+                raise ValueError('dimension mismatch')
             return self._mul_sparse_matrix(other)
 
         try:

Modified: trunk/scipy/sparse/tests/test_base.py
===================================================================
--- trunk/scipy/sparse/tests/test_base.py	2008-12-27 21:52:58 UTC (rev 5293)
+++ trunk/scipy/sparse/tests/test_base.py	2008-12-27 23:34:08 UTC (rev 5294)
@@ -446,6 +446,12 @@
         assert_array_almost_equal(B.todense(), A.todense() * A.T.todense())
         assert_array_almost_equal(B.todense(), A.todense() * A.todense().T)
 
+
+        # check dimension mismatch  2x2 times 3x2
+        A = self.spmatrix( [[1,2],[3,4]] )
+        B = self.spmatrix( [[1,2],[3,4],[5,6]] )
+        assert_raises(ValueError, A.__mul__, B)
+
     def test_matmat_dense(self):
         a = matrix([[3,0,0],[0,1,0],[2,0,3.0],[2,3,0]])
         asp = self.spmatrix(a)



More information about the Scipy-svn mailing list