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

scipy-svn at scipy.org scipy-svn at scipy.org
Sat Jan 15 09:02:06 EST 2011


Author: ptvirtan
Date: 2011-01-15 08:02:05 -0600 (Sat, 15 Jan 2011)
New Revision: 7043

Modified:
   trunk/scipy/linalg/matfuncs.py
   trunk/scipy/linalg/tests/test_matfuncs.py
Log:
BUG: linalg/expm2: revert r7037, and fix the fix; also add tests

Modified: trunk/scipy/linalg/matfuncs.py
===================================================================
--- trunk/scipy/linalg/matfuncs.py	2011-01-15 14:01:47 UTC (rev 7042)
+++ trunk/scipy/linalg/matfuncs.py	2011-01-15 14:02:05 UTC (rev 7043)
@@ -91,7 +91,11 @@
         t = 'd'
     s,vr = eig(A)
     vri = inv(vr)
-    return dot(dot(vr,diag(exp(s))),vri).real.astype(t)
+    r = dot(dot(vr,diag(exp(s))),vri)
+    if t in ['f', 'd']:
+        return r.real.astype(t)
+    else:
+        return r.astype(t)
 
 def expm3(A, q=20):
     """Compute the matrix exponential using Taylor series.

Modified: trunk/scipy/linalg/tests/test_matfuncs.py
===================================================================
--- trunk/scipy/linalg/tests/test_matfuncs.py	2011-01-15 14:01:47 UTC (rev 7042)
+++ trunk/scipy/linalg/tests/test_matfuncs.py	2011-01-15 14:02:05 UTC (rev 7043)
@@ -93,5 +93,14 @@
         assert_array_almost_equal(expm2(a),[[1,0],[0,1]])
         assert_array_almost_equal(expm3(a),[[1,0],[0,1]])
 
+    def test_consistency(self):
+        a = array([[0.,1],[-1,0]])
+        assert_array_almost_equal(expm(a), expm2(a))
+        assert_array_almost_equal(expm(a), expm3(a))
+
+        a = array([[1j,1],[-1,-2j]])
+        assert_array_almost_equal(expm(a), expm2(a))
+        assert_array_almost_equal(expm(a), expm3(a))
+
 if __name__ == "__main__":
     run_module_suite()




More information about the Scipy-svn mailing list