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

scipy-svn@scip... scipy-svn@scip...
Sun Oct 10 14:42:10 CDT 2010


Author: ptvirtan
Date: 2010-10-10 14:42:10 -0500 (Sun, 10 Oct 2010)
New Revision: 6832

Modified:
   trunk/scipy/linalg/basic.py
   trunk/scipy/linalg/tests/test_basic.py
Log:
BUG: linalg: fix residuals returned from linalg.lstsq for complex matrices

Modified: trunk/scipy/linalg/basic.py
===================================================================
--- trunk/scipy/linalg/basic.py	2010-10-10 05:40:50 UTC (rev 6831)
+++ trunk/scipy/linalg/basic.py	2010-10-10 19:42:10 UTC (rev 6832)
@@ -387,7 +387,7 @@
     if n < m:
         x1 = x[:n]
         if rank == n:
-            resids = sum(x[n:]**2, axis=0)
+            resids = sum(abs(x[n:])**2, axis=0)
         x = x1
     return x, resids, rank, s
 

Modified: trunk/scipy/linalg/tests/test_basic.py
===================================================================
--- trunk/scipy/linalg/tests/test_basic.py	2010-10-10 05:40:50 UTC (rev 6831)
+++ trunk/scipy/linalg/tests/test_basic.py	2010-10-10 19:42:10 UTC (rev 6832)
@@ -460,9 +460,16 @@
         a = [[1,2],[4,5],[3,4]]
         b = [1,2,3]
         x,res,r,s = lstsq(a,b)
-        #XXX: check defintion of res
         assert_array_almost_equal(x,direct_lstsq(a,b))
+        assert_almost_equal((abs(dot(a,x) - b)**2).sum(axis=0), res)
 
+    def test_simple_overdet_complex(self):
+        a = [[1+2j,2],[4,5],[3,4]]
+        b = [1,2+4j,3]
+        x,res,r,s = lstsq(a,b)
+        assert_array_almost_equal(x,direct_lstsq(a,b,cmplx=1))
+        assert_almost_equal(res, (abs(dot(a,x) - b)**2).sum(axis=0))
+
     def test_simple_underdet(self):
         a = [[1,2,3],[4,5,6]]
         b = [1,2]



More information about the Scipy-svn mailing list