From: Michael Orlitzky Date: Fri, 11 Nov 2016 01:22:55 +0000 (-0500) Subject: Figure out the base field automatically in condition_number(). X-Git-Tag: 0.1.0~46 X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=a4a3482192852e512ae1fed1a114d8314ec63ba8;p=dunshire.git Figure out the base field automatically in condition_number(). --- diff --git a/dunshire/matrices.py b/dunshire/matrices.py index 6d5bbc8..123085c 100644 --- a/dunshire/matrices.py +++ b/dunshire/matrices.py @@ -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]