[Scipy-svn] r2337 - trunk/Lib/linsolve

scipy-svn at scipy.org scipy-svn at scipy.org
Wed Nov 29 04:15:21 CST 2006


Author: rc
Date: 2006-11-29 04:15:15 -0600 (Wed, 29 Nov 2006)
New Revision: 2337

Modified:
   trunk/Lib/linsolve/linsolve.py
Log:
rhs shape check added

Modified: trunk/Lib/linsolve/linsolve.py
===================================================================
--- trunk/Lib/linsolve/linsolve.py	2006-11-29 01:03:53 UTC (rev 2336)
+++ trunk/Lib/linsolve/linsolve.py	2006-11-29 10:15:15 UTC (rev 2337)
@@ -43,6 +43,12 @@
     return mat
 
 def spsolve(A, b, permc_spec=2):
+    if b.ndim > 1:
+        if max( b.shape ) == b.size:
+            b = b.squeeze()
+        else:
+            raise ValueError, "rhs must be a vector (has shape %s)" % (b.shape,)
+    
     if not hasattr(A, 'tocsr') and not hasattr(A, 'tocsc'):
         raise ValueError, "sparse matrix must be able to return CSC format--"\
               "A.tocsc()--or CSR format--A.tocsr()"
@@ -51,8 +57,11 @@
                 " (rows, cols) = A.shape"
     M, N = A.shape
     if (M != N):
-        raise ValueError, "matrix must be square"
-
+        raise ValueError, "matrix must be square (has shape %s)" % (A.shape,)
+    if M != b.size:
+        raise ValueError, "matrix - rhs size mismatch (%s - %s)"\
+              % (A.shape, b.shape)
+       
     if isUmfpack and useUmfpack:
         mat = _toCS_umfpack( A )
 



More information about the Scipy-svn mailing list