]> gitweb.michael.orlitzky.com - dunshire.git/blobdiff - src/dunshire/matrices.py
Rename a variable to make pylint happy.
[dunshire.git] / src / dunshire / matrices.py
index a33259e6f3e71f7a4b5f2d47234464d80a9a3199..0d97c0cbc4e83dfc95231a2306b870fb7b93a5db 100644 (file)
@@ -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.
+    eigs = matrix(0, (domain_dim, 1), tc='d')
+    syev(real_matrix, eigs)
+    return list(eigs)
+
+
 def identity(domain_dim):
     """
     Return a ``domain_dim``-by-``domain_dim`` dense integer identity