Ë
    Ýbiª  ã                   óB   — d Z ddlmZ ddlmZ ddlmZ  G d„ de«      Zy)a,  
Copyright 2013 Steven Diamond

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
é    )ÚCone)Úcvxtypes)Úscopesc                   óx   ‡ — e Zd ZdZddˆ fd„Zdefd„Zddedefd„Zddedefd„Z	defd„Z
ed	„ «       Zd
„ Zˆ xZS )ÚPSDaI  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.
    Úreturnc                 ó´   •— t        |j                  «      dk7  s|j                  d   |j                  d   k7  rt        d«      ‚t        t        |   |g|«       y )Né   r   é   z2Non-square matrix in positive definite constraint.)ÚlenÚshapeÚ
ValueErrorÚsuperr   Ú__init__)ÚselfÚexprÚ	constr_idÚ	__class__s      €úP/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/constraints/psd.pyr   zPSD.__init__1   sO   ø€ äˆtz‰z‹?˜aÒ 4§:¡:¨a¡=°D·J±J¸q±MÒ#AÜØDóð ô 	Œc4Ñ! 4 &¨)Õ4ó    c                 ó&   — d| j                   d   z  S )Nz%s >> 0r   )Úargs©r   s    r   ÚnamezPSD.name9   s   € Ø˜4Ÿ9™9 Q™<Ñ'Ð'r   Údppc                 óÎ   — |r;t        j                  «       5  | j                  d   j                  «       cddd«       S | j                  d   j                  «       S # 1 sw Y   Œ&xY w)zIA PSD constraint is DCP if the constrained expression is affine.
        r   N)r   Ú	dpp_scoper   Ú	is_affine©r   r   s     r   Úis_dcpz
PSD.is_dcp<   sX   € ñ Ü×!Ñ!Ó#ñ 0Ø—y‘y ‘|×-Ñ-Ó/÷0ñ 0ày‰y˜‰|×%Ñ%Ó'Ð'÷0ð 0ús   —AÁA$c                  ó   — y)NF© r   s     r   Úis_dgpz
PSD.is_dgpD   s   € Ør   c                 ó"   — | j                  «       S ©N)r    r   s    r   Úis_dqcpzPSD.is_dqcpG   s   € Ø{‰{‹}Ðr   c                 ó   — | j                   j                  €y t        j                  «       | j                  d   | j                  d   j
                  z   «      dz  } t        j                  «       |«      j                  S )z_The residual of the constraint.

        Returns
        -------
        NumPy.ndarray
        Nr   r
   )r   Úvaluer   Ú
lambda_minr   ÚTÚneg)r   Úmin_eigs     r   ÚresidualzPSD.residualJ   sa   € ð 9‰9?‰?Ð"ØØ'”(×%Ñ%Ó'¨¯	©	°!©°t·y±yÀ±|·~±~Ñ(EÓFÀqÑHˆØŒx|‰|‹~˜gÓ&×,Ñ,Ð,r   c                 ó  — |€| j                   d   dz	  S |D cg c]  }|j                  ‘Œ }}| j                  D cg c]  }|j                  ‘Œ }}t        |«      t        | j                  «      k(  sJ ‚||k(  sJ ‚|d   dz	  S c c}w c c}w )zoImplements the dual cone of the PSD cone See Pg 85 of the
        MOSEK modelling cookbook for more informationr   )Údual_variablesr   r   r   )r   r   ÚargÚargs_shapesÚinstance_args_shapess        r   Ú
_dual_conezPSD._dual_coneW   s“   € ð ˆ<Ø×&Ñ& qÑ)¨QÑ.Ð.ð 15Ö5¨˜3Ÿ9›9Ð5ˆKÐ5Ø9=¿¹Ö#C°# C§I£IÐ#CÐ Ð#CÜt“9¤ D§I¡I£Ò.Ð.Ð.ØÐ"6Ò6Ð6Ð6Ø˜‘7˜a‘<Ðùò	 6ùÚ#Cs
   ™B¼Br%   )r   N)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ústrr   Úboolr    r#   r&   Úpropertyr-   r3   Ú__classcell__)r   s   @r   r   r      sd   ø„ ñö45ð(có (ñ(˜$ð (¨4ó (ñ˜$ð ¨4ó ð˜ó ð ñ
-ó ð
-ö r   r   N)r7   Úcvxpy.constraints.conesr   Úcvxpy.expressionsr   Úcvxpy.utilitiesr   r   r"   r   r   ú<module>r?      s#   ðñõ  )Ý &Ý "ôL ˆ$õ L r   