X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=mjo%2Fcone%2Fsymmetric_psd.py;h=ef5d477ce67aa4f40a3466c48904888ddfaa840b;hb=bcdc6431e034e6f7a9d6ddcb3282cecadfab597b;hp=514d0392c1fbe4fbae72057a87fd5524744c0668;hpb=a4f22c00f915d4c20f5105039d647540c18b3d83;p=sage.d.git diff --git a/mjo/cone/symmetric_psd.py b/mjo/cone/symmetric_psd.py index 514d039..ef5d477 100644 --- a/mjo/cone/symmetric_psd.py +++ b/mjo/cone/symmetric_psd.py @@ -6,14 +6,6 @@ all symmetric positive-semidefinite matrices (as a subset of from sage.all import * -# Sage doesn't load ~/.sage/init.sage during testing (sage -t), so we -# have to explicitly mangle our sitedir here so that "mjo.symbolic" -# resolves. -from os.path import abspath -from site import addsitedir -addsitedir(abspath('../../')) - - def is_symmetric_psd(A): """ Determine whether or not the matrix ``A`` is symmetric @@ -28,6 +20,10 @@ def is_symmetric_psd(A): Either ``True`` if ``A`` is symmetric positive-semidefinite, or ``False`` otherwise. + SETUP:: + + sage: from mjo.cone.symmetric_psd import is_symmetric_psd + EXAMPLES: Every completely positive matrix is symmetric @@ -80,6 +76,10 @@ def unit_eigenvectors(A): A list of (eigenvalue, eigenvector) pairs where each eigenvector is associated with its paired eigenvalue of ``A`` and has norm `1`. + SETUP:: + + sage: from mjo.cone.symmetric_psd import unit_eigenvectors + EXAMPLES:: sage: A = matrix(QQ, [[0, 2, 3], [2, 0, 0], [3, 0, 0]]) @@ -145,6 +145,10 @@ def factor_psd(A): `$D$` will have dimension `$k \times k$`. In the end everything works out the same. + SETUP:: + + sage: from mjo.cone.symmetric_psd import factor_psd + EXAMPLES: Create a symmetric positive-semidefinite matrix over the symbolic @@ -241,6 +245,10 @@ def random_psd(V, accept_zero=True, rank=None): ``accept_zero`` is ``False``, we restart the process from the beginning. + SETUP:: + + sage: from mjo.cone.symmetric_psd import is_symmetric_psd, random_psd + EXAMPLES: Well, it doesn't crash at least:: @@ -300,9 +308,8 @@ def random_psd(V, accept_zero=True, rank=None): # Use the one the user gave us. rank_A = rank - # Begin with the zero matrix, and add projectors to it if we have - # any. - A = V.zero_element().column()*V.zero_element().row() + # Begin with the zero matrix, and add projectors to it if we have any. + A = V.zero().column()*V.zero().row() # Careful, begin at idx=1 so that we only generate a projector # when rank_A is greater than zero.