]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
mjo/cone/doubly_nonnegative.py: don't import from sage.all
authorMichael Orlitzky <michael@orlitzky.com>
Fri, 22 Nov 2024 20:43:58 +0000 (15:43 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Fri, 22 Nov 2024 20:43:58 +0000 (15:43 -0500)
mjo/cone/doubly_nonnegative.py

index 5e10e1aebaad4c17de9e129681a57bb736e72886..71eb06bc233a7842262527fa8bde58f46d619449 100644 (file)
@@ -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() ):