]> gitweb.michael.orlitzky.com - dunshire.git/blobdiff - src/dunshire/matrices.py
Test that vec() is a no-op on vectors.
[dunshire.git] / src / dunshire / matrices.py
index 5acc7a876e417beafd259d416f59fc283c1c5f67..7bfc429bdd5651b10e07cae79a653e1e3cc925b5 100644 (file)
@@ -55,9 +55,9 @@ def eigenvalues(real_matrix):
 
     """
     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)
+    eigs = matrix(0, (domain_dim, 1), tc='d')
+    syev(real_matrix, eigs)
+    return list(eigs)
 
 
 def identity(domain_dim):
@@ -101,3 +101,42 @@ def norm(matrix_or_vector):
 
     """
     return sqrt(sum([x**2 for x in matrix_or_vector]))
+
+
+def vec(real_matrix):
+    """
+    Create a long vector in column-major order from ``real_matrix``.
+
+    EXAMPLES:
+
+        >>> A = matrix([[1,2],[3,4]])
+        >>> print(A)
+        [ 1  3]
+        [ 2  4]
+        <BLANKLINE>
+
+        >>> print(vec(A))
+        [ 1]
+        [ 2]
+        [ 3]
+        [ 4]
+        <BLANKLINE>
+
+    Note that if ``real_matrix`` is a vector, this function is a no-op:
+
+        >>> v = matrix([1,2,3,4], (4,1))
+        >>> print(v)
+        [ 1]
+        [ 2]
+        [ 3]
+        [ 4]
+        <BLANKLINE>
+        >>> print(vec(v))
+        [ 1]
+        [ 2]
+        [ 3]
+        [ 4]
+        <BLANKLINE>
+
+    """
+    return matrix(real_matrix, (len(real_matrix), 1))