From f9c11a761f23f781495171c2b3136a92388a18a1 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 6 Oct 2016 14:40:42 -0400 Subject: [PATCH] Add an eigenvalues() method to matrices.py. --- src/dunshire/matrices.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/dunshire/matrices.py b/src/dunshire/matrices.py index a33259e..5acc7a8 100644 --- a/src/dunshire/matrices.py +++ b/src/dunshire/matrices.py @@ -5,6 +5,7 @@ Utility functions for working with CVXOPT matrices (instances of the from math import sqrt from cvxopt import matrix +from cvxopt.lapack import syev def append_col(left, right): """ @@ -41,6 +42,24 @@ def append_row(top, bottom): """ return matrix([top, bottom]) + +def eigenvalues(real_matrix): + """ + Return the eigenvalues of the given ``real_matrix``. + + EXAMPLES: + + >>> A = matrix([[2,1],[1,2]], tc='d') + >>> eigenvalues(A) + [1.0, 3.0] + + """ + domain_dim = real_matrix.size[0] # Assume ``real_matrix`` is square. + W = matrix(0, (domain_dim, 1), tc='d') + syev(real_matrix, W) + return list(W) + + def identity(domain_dim): """ Return a ``domain_dim``-by-``domain_dim`` dense integer identity -- 2.44.2