Source code for cvxpy.constraints.psd

"""

you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
[docs]class PSD(Constraint): """A constraint of the form :math:\\frac{1}{2}(X + X^T) \\succcurlyeq_{S_n^+} 0 Applying a PSD constraint to a two-dimensional expression X constrains its symmetric part to be positive semidefinite: i.e., it constrains X to be such that .. math:: z^T(X + X^T)z \\geq 0, for all :math:z. The preferred way of creating a PSD constraint is through operator overloading. To constrain an expression X to be PSD, write X >> 0; to constrain it to be negative semidefinite, write X << 0. Strict definiteness constraints are not provided, as they do not make sense in a numerical setting. Parameters ---------- expr : Expression. The expression to constrain; *must* be two-dimensional. constr_id : int A unique id for the constraint. """ def __init__(self, expr, constr_id=None): # Argument must be square matrix. if len(expr.shape) != 2 or expr.shape[0] != expr.shape[1]: raise ValueError( "Non-square matrix in positive definite constraint." ) super(PSD, self).__init__([expr], constr_id) def name(self): return "%s >> 0" % self.args[0]