X-Git-Url: https://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Fdunshire%2Fcones.py;h=7fc8bf94993e4df86b2f57c2e6b6d6aefa65d8c4;hb=08abee864006192c364c25f22c3755e89e310b9b;hp=92a03a96245e79db4bce92f013e782c1964bf458;hpb=556f614c2cbbe91e34967ea78464436413ae1c75;p=dunshire.git diff --git a/src/dunshire/cones.py b/src/dunshire/cones.py index 92a03a9..7fc8bf9 100644 --- a/src/dunshire/cones.py +++ b/src/dunshire/cones.py @@ -4,8 +4,9 @@ Class definitions for all of the symmetric cones (and their superclass, """ from cvxopt import matrix -from matrices import eigenvalues, norm -import options + +from .matrices import eigenvalues, norm +from . import options class SymmetricCone: """ @@ -384,10 +385,10 @@ class SymmetricPSD(SymmetricCone): >>> K = SymmetricPSD(5) >>> A = matrix([[5,4,3,2,1], - ... [4,5,4,3,2], - ... [3,4,5,4,3], - ... [2,3,4,5,4], - ... [1,2,3,4,5]]) + ... [4,5,4,3,2], + ... [3,4,5,4,3], + ... [2,3,4,5,4], + ... [1,2,3,4,5]]) >>> A in K True @@ -409,8 +410,16 @@ class SymmetricPSD(SymmetricCone): However, this matrix has a negative eigenvalue: >>> K = SymmetricPSD(2) - >>> A = matrix([[1,-2], - ... [-2,1]]) + >>> A = matrix([[ 1, -2], + ... [-2, 1]]) + >>> A in K + False + + An asymmetric cone with positive eigenvalues is not in the cone: + + >>> K = SymmetricPSD(2) + >>> A = matrix([[10, 2], + ... [4, 8]]) >>> A in K False @@ -435,6 +444,9 @@ class SymmetricPSD(SymmetricCone): raise TypeError('the given point has the wrong dimensions') if not point.typecode == 'd': point = matrix(point, (self.dimension(), self.dimension()), 'd') + if not norm(point - point.trans()) < options.ABS_TOL: + # It's not symmetric. + return False return all([e > -options.ABS_TOL for e in eigenvalues(point)])