]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/cone/doubly_nonnegative.py
Refactor symmetric_pds/doubly_nonnegative.
[sage.d.git] / mjo / cone / doubly_nonnegative.py
index b071e41dc332a709a527588bd8f665e80eeb4c17..f705e5e98b083d6cf85fac39148d171cdf452d99 100644 (file)
@@ -19,7 +19,7 @@ from sage.all import *
 from os.path import abspath
 from site import addsitedir
 addsitedir(abspath('../../'))
-from mjo.cone.symmetric_psd import factor_psd
+from mjo.cone.symmetric_psd import factor_psd, is_symmetric_psd
 
 
 
@@ -54,22 +54,16 @@ def is_doubly_nonnegative(A):
     """
 
     if A.base_ring() == SR:
-        msg = 'The base ring of ``A`` cannot be the Symbolic Ring'
+        msg = 'The matrix ``A`` cannot be the symbolic.'
         raise ValueError.new(msg)
 
-    # First make sure that ``A`` is symmetric.
-    if not A.is_symmetric():
-        return False
-
     # Check that all of the entries of ``A`` are nonnegative.
     if not all([ a >= 0 for a in A.list() ]):
         return False
 
-    # If ``A`` is symmetric and non-negative, we only need to check
-    # that it is positive semidefinite. For that we can consult its
-    # minimum eigenvalue, which should be zero or greater. Since ``A``
-    # is symmetric, its eigenvalues are guaranteed to be real.
-    return min(A.eigenvalues()) >= 0
+    # It's nonnegative, so all we need to do is check that it's
+    # symmetric positive-semidefinite.
+    return is_symmetric_psd(A)