From 002b5370da24f083d2088c3482cf076615a13563 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 6 Oct 2016 18:02:54 -0400 Subject: [PATCH] Fix SymmetricPSD documentation and add the column-major vec() function. --- src/dunshire/cones.py | 13 ++++++++++++- src/dunshire/matrices.py | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/dunshire/cones.py b/src/dunshire/cones.py index b1e07e9..2609b16 100644 --- a/src/dunshire/cones.py +++ b/src/dunshire/cones.py @@ -316,13 +316,24 @@ class IceCream(SymmetricCone): class SymmetricPSD(SymmetricCone): """ - The nonnegative orthant in ``n`` dimensions. + The cone of real symmetric positive-semidefinite matrices. + + This cone has a dimension ``n`` associated with it, but we let ``n`` + refer to the dimension of the domain of our matrices and not the + dimension of the (much larger) space in which the matrices + themselves live. In other words, our ``n`` is the ``n`` that appears + in the usual notation `S^{n}` for symmetric matrices. + + As a result, the cone ``SymmetricPSD(n)`` lives in a space of dimension + ``(n**2 + n)/2)``. EXAMPLES: >>> K = SymmetricPSD(3) >>> print(K) Cone of symmetric positive-semidefinite matrices on the real 3-space + >>> K.dimension() + 3 """ def __str__(self): diff --git a/src/dunshire/matrices.py b/src/dunshire/matrices.py index 0d97c0c..1e0f2a5 100644 --- a/src/dunshire/matrices.py +++ b/src/dunshire/matrices.py @@ -101,3 +101,26 @@ 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] + + + >>> print(vec(A)) + [ 1] + [ 2] + [ 3] + [ 4] + + + """ + return matrix(real_matrix, (len(real_matrix), 1)) -- 2.44.2