[Scipy-svn] r6812 - in trunk/scipy/sparse/linalg/eigen/arpack: . tests

scipy-svn@scip... scipy-svn@scip...
Fri Sep 17 23:58:40 CDT 2010


Author: warren.weckesser
Date: 2010-09-17 23:58:40 -0500 (Fri, 17 Sep 2010)
New Revision: 6812

Modified:
   trunk/scipy/sparse/linalg/eigen/arpack/arpack.py
   trunk/scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py
Log:
BUG: sparse: Incorrect formatting in the eigen() function of arpack.py resulted in a TypeError instead of a ValueError when a matrix with an invalid shape was given.

Modified: trunk/scipy/sparse/linalg/eigen/arpack/arpack.py
===================================================================
--- trunk/scipy/sparse/linalg/eigen/arpack/arpack.py	2010-09-18 04:41:54 UTC (rev 6811)
+++ trunk/scipy/sparse/linalg/eigen/arpack/arpack.py	2010-09-18 04:58:40 UTC (rev 6812)
@@ -383,7 +383,7 @@
     """
     A = aslinearoperator(A)
     if A.shape[0] != A.shape[1]:
-        raise ValueError('expected square matrix (shape=%s)' % A.shape)
+        raise ValueError('expected square matrix (shape=%s)' % (A.shape,))
     n = A.shape[0]
 
     matvec = lambda x : A.matvec(x)
@@ -476,7 +476,7 @@
     """
     A = aslinearoperator(A)
     if A.shape[0] != A.shape[1]:
-        raise ValueError('expected square matrix (shape=%s)' % shape)
+        raise ValueError('expected square matrix (shape=%s)' % (A.shape,))
     n = A.shape[0]
 
     if M is not None:
@@ -513,7 +513,7 @@
     n, m = A.shape
 
     if np.iscomplexobj(A):
-        raise NotImplementedError("Complex support for sparse SVD not " \
+        raise NotImplementedError("Complex support for sparse SVD not "
                                   "implemented yet")
         op = lambda x: x.T.conjugate()
     else:

Modified: trunk/scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py
===================================================================
--- trunk/scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py	2010-09-18 04:41:54 UTC (rev 6811)
+++ trunk/scipy/sparse/linalg/eigen/arpack/tests/test_arpack.py	2010-09-18 04:58:40 UTC (rev 6812)
@@ -8,9 +8,10 @@
 
 from numpy.testing import assert_almost_equal, assert_array_almost_equal, \
         assert_array_almost_equal_nulp, TestCase, run_module_suite, dec, \
-        verbose
+        assert_raises, verbose
 
 from numpy import array, finfo, argsort, dot, round, conj, random
+from scipy.sparse import csc_matrix
 from scipy.sparse.linalg.eigen.arpack import eigen_symmetric, eigen, svd
 
 from scipy.linalg import svd as dsvd
@@ -155,10 +156,9 @@
         k=2
         for typ in 'FD':
             for which in ['LM','SM','LR','SR']:
-                self.eval_evec(self.symmetric[0],typ,k,which)
+                self.eval_evec(self.symmetric[0],typ,k,which)        
 
 
-
 class TestEigenNonSymmetric(TestArpack):
 
 
@@ -268,6 +268,13 @@
                 for m in self.nonsymmetric:
                     self.eval_evec(m,typ,k,which)
 
+
+def test_eigen_bad_shapes():
+    # A is not square.
+    A = csc_matrix(np.zeros((2,3)))
+    assert_raises(ValueError, eigen, A)
+
+
 def sorted_svd(m, k):
     """Compute svd of a dense matrix m, and return singular vectors/values
     sorted."""



More information about the Scipy-svn mailing list