From a4a3482192852e512ae1fed1a114d8314ec63ba8 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 10 Nov 2016 20:22:55 -0500 Subject: [PATCH] Figure out the base field automatically in condition_number(). --- dunshire/matrices.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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] -- 2.44.2