X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2Fdunshire%2Fcones.py;h=61feab453bd0866b54c053d2871d722a63ec3730;hb=23a5893ede3a22653128d3e7a66fb3f6b80616b8;hp=870a882423e6180ea0e4256e5f7c05f17aac6d4f;hpb=6aff913423ca1f1ec2434650a6065d18a2f6415f;p=dunshire.git diff --git a/src/dunshire/cones.py b/src/dunshire/cones.py index 870a882..61feab4 100644 --- a/src/dunshire/cones.py +++ b/src/dunshire/cones.py @@ -384,10 +384,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 +409,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 +443,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)]) @@ -539,7 +550,7 @@ class CartesianProduct(SymmetricCone): TypeError: the given point has the wrong dimensions """ - return all([p in f for (p,f) in zip(point, self.factors())]) + return all([p in f for (p, f) in zip(point, self.factors())])