From fee82e940853ec38dac98c45b1895a1a069c2493 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 22 Nov 2024 15:43:58 -0500 Subject: [PATCH] mjo/cone/doubly_nonnegative.py: don't import from sage.all --- mjo/cone/doubly_nonnegative.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/mjo/cone/doubly_nonnegative.py b/mjo/cone/doubly_nonnegative.py index 5e10e1a..71eb06b 100644 --- a/mjo/cone/doubly_nonnegative.py +++ b/mjo/cone/doubly_nonnegative.py @@ -8,16 +8,8 @@ that both, It is represented typically by either `\mathcal{D}^{n}` or `\mathcal{DNN}`. - """ -from sage.all import * - -from mjo.cone.symmetric_psd import (factor_psd, - random_symmetric_psd) -from mjo.basis_repr import basis_repr - - def is_doubly_nonnegative(A): """ Determine whether or not the matrix ``A`` is doubly-nonnegative. @@ -51,6 +43,7 @@ def is_doubly_nonnegative(A): False """ + from sage.symbolic.ring import SR if A.base_ring() == SR: msg = 'The matrix ``A`` cannot be the symbolic.' @@ -197,7 +190,8 @@ def has_admissible_extreme_rank(A): # something unexpected. raise ValueError('The matrix ``A`` must be symmetric.') - r = rank(A) + from sage.rings.all import ZZ + r = A.rank() n = ZZ(A.nrows()) # Columns would work, too, since ``A`` is symmetric. return is_admissible_extreme_rank(r,n) @@ -312,10 +306,10 @@ def is_extreme_doubly_nonnegative(A): sage: A = A.change_ring(QQ) sage: is_extreme_doubly_nonnegative(A) True - sage: v = vector(map(abs, random_vector(ZZ, 10))) + sage: v = vector(map(abs, random_vector(ZZ, 8))) sage: A = v.column() * v.row() sage: A = A.change_ring(QQ) - sage: is_extreme_doubly_nonnegative(A) + sage: is_extreme_doubly_nonnegative(A) # long time True The following matrix is completely positive but has rank 3, so by a @@ -333,6 +327,8 @@ def is_extreme_doubly_nonnegative(A): False """ + from sage.modules.free_module import VectorSpace + 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.' @@ -362,6 +358,7 @@ def is_extreme_doubly_nonnegative(A): return False # Step 2 + from mjo.cone.symmetric_psd import factor_psd X = factor_psd(A) # Step 3 @@ -382,11 +379,12 @@ def is_extreme_doubly_nonnegative(A): # can't compute the dimension of a set of matrices anyway, so we # convert them all to vectors and just ask for the dimension of the # resulting vector space. + from mjo.basis_repr import basis_repr (phi, phi_inverse) = basis_repr(A.matrix_space()) vectors = map(phi,spanning_set) - V = span(vectors, A.base_ring()) - d = V.dimension() + V = VectorSpace(A.base_ring(), A.nrows()*A.ncols()) + d = V.span(vectors).dimension() # Needed to safely divide by two here (we don't want integer # division). We ensured that the base ring of ``A`` is a field @@ -459,6 +457,7 @@ 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. + from mjo.cone.symmetric_psd import random_symmetric_psd A = random_symmetric_psd(V, accept_zero, rank) while not all( x >= 0 for x in A.list() ): -- 2.49.0