From e0fe78330d18566d75a74bd4e58d415e3a9d5889 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 30 Nov 2018 11:00:57 -0500 Subject: [PATCH] mjo/cone: rename random_psd() to random_symmetric_psd(). --- mjo/cone/doubly_nonnegative.py | 8 +++++--- mjo/cone/symmetric_psd.py | 21 +++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/mjo/cone/doubly_nonnegative.py b/mjo/cone/doubly_nonnegative.py index 92184d1..a30a827 100644 --- a/mjo/cone/doubly_nonnegative.py +++ b/mjo/cone/doubly_nonnegative.py @@ -13,7 +13,9 @@ It is represented typically by either `\mathcal{D}^{n}` or from sage.all import * -from mjo.cone.symmetric_psd import factor_psd, is_symmetric_psd, random_psd +from mjo.cone.symmetric_psd import (factor_psd, + is_symmetric_psd, + random_symmetric_psd) from mjo.matrix_vector import isomorphism @@ -458,10 +460,10 @@ def random_doubly_nonnegative(V, accept_zero=True, rank=None): # Generate random symmetric positive-semidefinite matrices until # one of them is nonnegative, then return that. - A = random_psd(V, accept_zero, rank) + A = random_symmetric_psd(V, accept_zero, rank) while not all( x >= 0 for x in A.list() ): - A = random_psd(V, accept_zero, rank) + A = random_symmetric_psd(V, accept_zero, rank) return A diff --git a/mjo/cone/symmetric_psd.py b/mjo/cone/symmetric_psd.py index 1b3dd8a..e75c152 100644 --- a/mjo/cone/symmetric_psd.py +++ b/mjo/cone/symmetric_psd.py @@ -201,7 +201,7 @@ def factor_psd(A): return Q*root_D*Q.transpose() -def random_psd(V, accept_zero=True, rank=None): +def random_symmetric_psd(V, accept_zero=True, rank=None): """ Generate a random symmetric positive-semidefinite matrix over the vector space ``V``. That is, the returned matrix will be a linear @@ -242,14 +242,15 @@ def random_psd(V, accept_zero=True, rank=None): SETUP:: - sage: from mjo.cone.symmetric_psd import is_symmetric_psd, random_psd + sage: from mjo.cone.symmetric_psd import (is_symmetric_psd, + ....: random_symmetric_psd) EXAMPLES: Well, it doesn't crash at least:: sage: V = VectorSpace(QQ, 2) - sage: A = random_psd(V) + sage: A = random_symmetric_psd(V) sage: A.matrix_space() Full MatrixSpace of 2 by 2 dense matrices over Rational Field sage: is_symmetric_psd(A) @@ -258,26 +259,26 @@ def random_psd(V, accept_zero=True, rank=None): A matrix with the desired rank is returned:: sage: V = VectorSpace(QQ, 5) - sage: A = random_psd(V,False,1) + sage: A = random_symmetric_psd(V,False,1) sage: A.rank() 1 - sage: A = random_psd(V,False,2) + sage: A = random_symmetric_psd(V,False,2) sage: A.rank() 2 - sage: A = random_psd(V,False,3) + sage: A = random_symmetric_psd(V,False,3) sage: A.rank() 3 - sage: A = random_psd(V,False,4) + sage: A = random_symmetric_psd(V,False,4) sage: A.rank() 4 - sage: A = random_psd(V,False,5) + sage: A = random_symmetric_psd(V,False,5) sage: A.rank() 5 If the user asks for a rank that's too high, we fail:: sage: V = VectorSpace(QQ, 2) - sage: A = random_psd(V,False,3) + sage: A = random_symmetric_psd(V,False,3) Traceback (most recent call last): ... ValueError: The ``rank`` must be between 0 and the dimension of ``V``. @@ -318,4 +319,4 @@ def random_psd(V, accept_zero=True, rank=None): return A else: # Uh oh, we need to generate a new one. - return random_psd(V, accept_zero, rank) + return random_symmetric_psd(V, accept_zero, rank) -- 2.44.2