]> gitweb.michael.orlitzky.com - dunshire.git/commitdiff
Figure out the base field automatically in condition_number().
authorMichael Orlitzky <michael@orlitzky.com>
Fri, 11 Nov 2016 01:22:55 +0000 (20:22 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Sun, 13 Nov 2016 20:19:26 +0000 (15:19 -0500)
dunshire/matrices.py

index 6d5bbc8f667dce05feb93ec9fabcf42340f1157e..123085c6c02f69574dc614fcff49d46207b7981c 100644 (file)
@@ -422,21 +422,25 @@ def condition_number(mat):
     Examples
     --------
 
-    >>> condition_number(identity(3, typecode='d'))
+    >>> condition_number(identity(3))
     1.0
 
-    >>> A = matrix([[2,1],[1,2]], tc='d')
+    >>> A = matrix([[2,1],[1,2]])
     >>> abs(condition_number(A) - 3.0) < options.ABS_TOL
     True
 
-    >>> A = matrix([[2,1j],[-1j,2]], tc='z')
+    >>> A = matrix([[2,1j],[-1j,2]])
     >>> abs(condition_number(A) - 3.0) < options.ABS_TOL
     True
 
     """
     num_eigs = min(mat.size)
     eigs = matrix(0, (num_eigs, 1), tc='d')
-    gesdd(mat, eigs)
+    typecode = 'd'
+    if any([isinstance(entry, complex) for entry in mat]):
+        typecode = 'z'
+    dummy = matrix(mat, mat.size, tc=typecode)
+    gesdd(dummy, eigs)
 
     if len(eigs) > 0:
         return eigs[0]/eigs[-1]