From e8863109b3e0a7de183a73b7ee607d56cc5dde18 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 22 Nov 2024 16:38:30 -0500 Subject: [PATCH] mjo/cone/symmetric_psd.py: don't import from sage.all --- mjo/cone/symmetric_psd.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mjo/cone/symmetric_psd.py b/mjo/cone/symmetric_psd.py index d711773..8b435e1 100644 --- a/mjo/cone/symmetric_psd.py +++ b/mjo/cone/symmetric_psd.py @@ -4,8 +4,6 @@ all symmetric positive-semidefinite matrices (as a subset of `$\mathbb{R}^{n \times n}$` """ -from sage.all import * - def unit_eigenvectors(A): """ Return the unit eigenvectors of a symmetric positive-definite matrix. @@ -117,6 +115,7 @@ def factor_psd(A): ValueError: The base ring of ``A`` must be a field. """ + from sage.symbolic.ring import SR if not A.base_ring().is_exact() and not A.base_ring() is SR: msg = 'The base ring of ``A`` must be either exact or symbolic.' @@ -136,10 +135,10 @@ def factor_psd(A): all_evs = unit_eigenvectors(A) evs = [ (val,vec) for (val,vec) in all_evs if not val == 0 ] + from sage.matrix.constructor import matrix d = ( val.sqrt() for (val,vec) in evs ) - root_D = diagonal_matrix(d).change_ring(A.base_ring()) - - Q = matrix(A.base_ring(), ( vec for (val,vec) in evs )).transpose() + root_D = matrix.diagonal(d).change_ring(A.base_ring()) + Q = matrix.column(A.base_ring(), ( vec for (val,vec) in evs )) return Q*root_D*Q.transpose() @@ -237,6 +236,7 @@ def random_symmetric_psd(V, accept_zero=True, rank=None): rank_A = 0 if rank is None: # Choose one randomly + from sage.rings.all import ZZ rank_A = ZZ.random_element(n+1) elif (rank < 0) or (rank > n): # The rank of ``A`` can be at most ``n``. @@ -251,6 +251,7 @@ def random_symmetric_psd(V, accept_zero=True, rank=None): raise ValueError('You must have accept_zero=True when V is trivial') # Loop until we find a suitable "A" that will then be returned. + from sage.matrix.constructor import matrix while True: # Begin with the zero matrix, and add projectors to it if we # have any. -- 2.49.0