[Scipy-svn] r6265 - in trunk/scipy/linalg: . tests

scipy-svn at scipy.org scipy-svn at scipy.org
Sun Mar 21 16:37:15 EDT 2010


Author: warren.weckesser
Date: 2010-03-21 15:37:15 -0500 (Sun, 21 Mar 2010)
New Revision: 6265

Modified:
   trunk/scipy/linalg/decomp.py
   trunk/scipy/linalg/tests/test_decomp.py
Log:
BUG: Add check that both matrices have the same shape when the generalized eigenvalue problem is being solve (fix for ticket 1113).

Modified: trunk/scipy/linalg/decomp.py
===================================================================
--- trunk/scipy/linalg/decomp.py	2010-03-21 19:41:30 UTC (rev 6264)
+++ trunk/scipy/linalg/decomp.py	2010-03-21 20:37:15 UTC (rev 6265)
@@ -150,10 +150,12 @@
     """
     a1 = asarray_chkfinite(a)
     if len(a1.shape) != 2 or a1.shape[0] != a1.shape[1]:
-        raise ValueError, 'expected square matrix'
+        raise ValueError('expected square matrix')
     overwrite_a = overwrite_a or (_datanotshared(a1,a))
     if b is not None:
         b = asarray_chkfinite(b)
+        if b.shape != a1.shape:
+            raise ValueError('a and b must have the same shape')
         return _geneig(a1,b,left,right,overwrite_a,overwrite_b)
     geev, = get_lapack_funcs(('geev',),(a1,))
     compute_vl,compute_vr=left,right

Modified: trunk/scipy/linalg/tests/test_decomp.py
===================================================================
--- trunk/scipy/linalg/tests/test_decomp.py	2010-03-21 19:41:30 UTC (rev 6264)
+++ trunk/scipy/linalg/tests/test_decomp.py	2010-03-21 20:37:15 UTC (rev 6265)
@@ -205,6 +205,18 @@
             if all(isfinite(res[:, i])):
                 assert_array_almost_equal(res[:, i], 0)
 
+    def test_not_square_error(self):
+        """Check that passing a non-square array raises a ValueError."""
+        A = np.arange(6).reshape(3,2)
+        assert_raises(ValueError, eig, A)
+
+    def test_shape_mismatch(self):
+        """Check that passing arrays of with different shapes raises a ValueError."""
+        A = identity(2)
+        B = np.arange(9.0).reshape(3,3)
+        assert_raises(ValueError, eig, A, B)
+        assert_raises(ValueError, eig, B, A)
+
 class TestEigBanded(TestCase):
 
     def __init__(self, *args):




More information about the Scipy-svn mailing list