]> gitweb.michael.orlitzky.com - dunshire.git/commitdiff
Add some more doctests for SymmetricPSD containment.
authorMichael Orlitzky <michael@orlitzky.com>
Thu, 6 Oct 2016 20:13:53 +0000 (16:13 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Thu, 6 Oct 2016 20:13:53 +0000 (16:13 -0400)
src/dunshire/cones.py

index 4176f573bb68b462c2cff38cf133970e5159a20e..b1e07e9d6c607c823334aecb74ea774cb073bf35 100644 (file)
@@ -342,16 +342,37 @@ class SymmetricPSD(SymmetricCone):
 
         An instance of the ``cvxopt.base.matrix`` class having
         dimensions ``(n,n)`` where ``n`` is the dimension of this cone.
-        Its type code must be 'd'.
 
         EXAMPLES:
 
             >>> K = SymmetricPSD(2)
-            >>> matrix([[1,0],[0,1]], tc='d') in K
+            >>> matrix([[1,0],[0,1]]) in K
             True
 
             >>> K = SymmetricPSD(2)
-            >>> matrix([[0,0],[0,0]], tc='d') in K
+            >>> matrix([[0,0],[0,0]]) in K
+            True
+
+            >>> K = SymmetricPSD(3)
+            >>> matrix([[2,-1,0],[-1,2,-1],[0,-1,2]]) in K
+            True
+
+            >>> 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]])
+            >>> A in K
+            True
+
+            >>> K = SymmetricPSD(5)
+            >>> A = matrix([[1,0,0,0,0],
+            ...            [0,1,0,0,0],
+            ...            [0,0,0,0,0],
+            ...            [0,0,0,1,0],
+            ...            [0,0,0,0,1]])
+            >>> A in K
             True
 
             >>> K = SymmetricPSD(2)
@@ -361,7 +382,7 @@ class SymmetricPSD(SymmetricCone):
             TypeError: the given point is not a cvxopt.base.matrix
 
             >>> K = SymmetricPSD(3)
-            >>> matrix([[1,2],[3,4]], tc='d') in K
+            >>> matrix([[1,2],[3,4]]) in K
             Traceback (most recent call last):
             ...
             TypeError: the given point has the wrong dimensions
@@ -371,6 +392,8 @@ class SymmetricPSD(SymmetricCone):
             raise TypeError('the given point is not a cvxopt.base.matrix')
         if not point.size == (self.dimension(), self.dimension()):
             raise TypeError('the given point has the wrong dimensions')
+        if not point.typecode == 'd':
+            point = matrix(point, (self.dimension(), self.dimension()), 'd')
         return all([e >= 0 for e in eigenvalues(point)])
 
 
@@ -388,11 +411,33 @@ class SymmetricPSD(SymmetricCone):
         EXAMPLES:
 
             >>> K = SymmetricPSD(2)
-            >>> K.contains_strict(matrix([[1,0],[0,1]], tc='d'))
+            >>> K.contains_strict(matrix([[1,0],[0,1]]))
             True
 
             >>> K = SymmetricPSD(2)
-            >>> K.contains_strict(matrix([[0,0],[0,0]], tc='d'))
+            >>> K.contains_strict(matrix([[0,0],[0,0]]))
+            False
+
+            >>> K = SymmetricPSD(3)
+            >>> matrix([[2,-1,0],[-1,2,-1],[0,-1,2]]) in K
+            True
+
+            >>> 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]])
+            >>> A in K
+            True
+
+            >>> K = SymmetricPSD(5)
+            >>> A = matrix([[1,0,0,0,0],
+            ...            [0,1,0,0,0],
+            ...            [0,0,0,0,0],
+            ...            [0,0,0,1,0],
+            ...            [0,0,0,0,1]])
+            >>> K.contains_strict(A)
             False
 
             >>> K = SymmetricPSD(2)
@@ -402,7 +447,7 @@ class SymmetricPSD(SymmetricCone):
             TypeError: the given point is not a cvxopt.base.matrix
 
             >>> K = SymmetricPSD(3)
-            >>> K.contains_strict(matrix([[1,2],[3,4]], tc='d'))
+            >>> K.contains_strict(matrix([[1,2],[3,4]]))
             Traceback (most recent call last):
             ...
             TypeError: the given point has the wrong dimensions
@@ -412,6 +457,8 @@ class SymmetricPSD(SymmetricCone):
             raise TypeError('the given point is not a cvxopt.base.matrix')
         if not point.size == (self.dimension(), self.dimension()):
             raise TypeError('the given point has the wrong dimensions')
+        if not point.typecode == 'd':
+            point = matrix(point, (self.dimension(), self.dimension()), 'd')
         return all([e > 0 for e in eigenvalues(point)])