X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=mjo%2Fcone%2Fdoubly_nonnegative.py;h=f705e5e98b083d6cf85fac39148d171cdf452d99;hb=3a800989b6e935fdab52418ac644d926997b83d0;hp=b071e41dc332a709a527588bd8f665e80eeb4c17;hpb=3076563f6dc460b219cc3b27f8538d427b297604;p=sage.d.git diff --git a/mjo/cone/doubly_nonnegative.py b/mjo/cone/doubly_nonnegative.py index b071e41..f705e5e 100644 --- a/mjo/cone/doubly_nonnegative.py +++ b/mjo/cone/doubly_nonnegative.py @@ -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)