
    biE                     r    d Z ddlmZmZ ddlZddlmZ ddlm	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.
    )ListTupleN)linalg)Atom)
Constraintc                        e Zd ZdZd fdZd ZddZdeedf   fdZ	dee
e
f   fdZde
fd	Zde
fd
Zde
fdZde
fdZd Zdee   fdZedefd       Z xZS )log_detz:math:`\log\det A`

    returnc                 ,    t         t        |   |       y )N)superr	   __init__)selfA	__class__s     N/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/atoms/log_det.pyr   zlog_det.__init__!   s    gt%a(    c                     |d   t        j                  |d   j                        z   dz  }t        j                  |      \  }}t        j
                  t        j                  |      d      r|S t         j                   S )zReturns the logdet of PSD matrix A.

        For PSD matrix A, this is the sum of logs of eigenvalues of A
        and is equivalent to the nuclear norm of the matrix logarithm of A.
        r         )npconjTLAslogdetiscloserealinf)r   valuessymmsignlogdets        r   numericzlog_det.numeric$   s`     q	BGGF1IKK00!3zz$'f::bggdmQ'MFF7Nr   c                     | j                   d   }t        |j                        dk(  r|j                  d   |j                  d   k7  rt        d      y )Nr   r   r   z3The argument to log_det must be a 2-d square array.)argslenshape	TypeError)r   Xs     r   validate_argumentszlog_det.validate_arguments3   sG    IIaL177|q AGGAJ!''!*$<QRR %=r   .c                     t               S )z8Returns the (row, col) shape of the expression.
        )tupler   s    r   shape_from_argszlog_det.shape_from_args8   s     wr   c                      y)zCReturns sign (is positive, is negative) of the expression.
        )TF r,   s    r   sign_from_argszlog_det.sign_from_args=   s     r   c                      y)zIs the atom convex?
        Fr/   r,   s    r   is_atom_convexzlog_det.is_atom_convexB        r   c                      y)zIs the atom concave?
        Tr/   r,   s    r   is_atom_concavezlog_det.is_atom_concaveG   s     r   c                      y)z;Is the composition non-decreasing in argument idx?
        Fr/   r   idxs     r   is_incrzlog_det.is_incrL   r3   r   c                      y)z;Is the composition non-increasing in argument idx?
        Fr/   r7   s     r   is_decrzlog_det.is_decrQ   r3   r   c                     |d   }t        j                  |      }t        j                  |      dkD  rZt        j                  j                  |      j                  }t        j                  |j                  d      g      j                  gS dgS )a+  Gives the (sub/super)gradient of the atom w.r.t. each argument.

        Matrix expressions are vectorized, so the gradient is a matrix.

        Args:
            values: A list of numeric values for the arguments.

        Returns:
            A list of SciPy CSC sparse matrices or None.
        r   F)orderN)
r   eigvalshr   minr   invr   sp	csc_arrayravel)r   r   r(   	eigen_valDs        r   _gradzlog_det._gradV   sr     1IKKN	66)q 		a ""ALL!'''"4!568899 6Mr   c                 (    | j                   d   dz	  gS )z?Returns constraints describing the domain of the node.
        r   )r$   r,   s    r   _domainzlog_det._domaink   s     		!!""r   c                    t        j                  | j                  d   j                  | j                  d   j                  j                  j                         t        j                  t        j                        st        d      t        | j                         D cg c]  }|j                  d u  c}      ry | j                         S c c}w )Nr   )rtolatolz)Input matrix was not Hermitian/symmetric.)r   allcloser$   valuer   r   sATOM_EVAL_TOL
ValueErrorany
parameters_value_impl)r   ps     r   rN   zlog_det.valuep   s    {{499Q<--99Q<--//446 ! !1 HII):;A4;<!! <s   C)r
   N)__name__
__module____qualname____doc__r   r"   r)   r   intr-   boolr0   r2   r5   r9   r;   rG   r   r   rI   propertyfloatrN   __classcell__)r   s   @r   r	   r	      s    )S
sCx 
dDj 1 
 
 
d 
d 
*#j) #
 "u " "r   r	   )rY   typingr   r   numpyr   scipy.sparsesparserB   r   r   cvxpy.settingssettingsrO   cvxpy.atoms.atomr   cvxpy.constraints.constraintr   r	   r/   r   r   <module>rg      s/          ! 3]"d ]"r   