
    biW                     R    d Z ddlmZmZ ddlmZ ddlmZ ddl	m
Z
  G d de      Zy)	a0  
Copyright 2022, the CVXPY authors

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Tuple)linalg)Atom)
Constraintc                        e Zd ZdZd fdZd Zdee   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efdZ xZS )condition_numberz Condition Number; :math:`\lambda_{\max}(A) / \lambda_{\min}(A)`.
        Requires that A be a Positive Semidefinite Matrix.
    returnc                 ,    t         t        |   |       y )N)superr	   __init__)selfA	__class__s     W/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/atoms/condition_number.pyr   zcondition_number.__init__   s    .q1    c                     | j                   d   j                  d   dz
  x}}t        j                  |d   ||f      d   }t        j                  |d    ||f      d    }||z  S )zgReturns the condition number of A.

        Requires that A be a Positive Semidefinite Matrix.
        r      )subset_by_index)argsshapeLAeigvalsh)r   valueslohi	max_eigen	min_eigens         r   numericzcondition_number.numeric   sp    
 ))A,$$Q'))RKKq	B8DQG	[[&)b"XFqII	9$$r   c                 x    | j                   d   j                  | j                   d   k(  | j                   d   dz	  gS )z?Returns constraints describing the domain of the node.
        r   )r   Hr   s    r   _domainzcondition_number._domain)   s5     		!$))A,.		!0ABBr   c                     t         )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.
        )NotImplementedError)r   r   s     r   _gradzcondition_number._grad.   s
     "!r   c                    | j                   d   j                  dk(  r9| j                   d   j                  d   | j                   d   j                  d   k7  r*t        d| j                   d   j	                          d      y)z7Verify that the argument A is a square matrix.
        r      r   zThe argument z/ to condition_number must be a 2-d square arrayN)r   ndimr   
ValueErrornamer"   s    r   validate_argumentsz#condition_number.validate_arguments;   sz     yy|  A%1););A)>$))A,BTBTUVBW)W		! 1 1 344cd  *Xr   .c                     t               S )z8Returns the (row, col) shape of the expression.
        )tupler"   s    r   shape_from_argsz condition_number.shape_from_argsC   s     wr   c                      y)zCReturns sign (is positive, is negative) of the expression.
        )TF r"   s    r   sign_from_argszcondition_number.sign_from_argsH   s     r   c                      y)zIs the atom convex?
        Fr1   r"   s    r   is_atom_convexzcondition_number.is_atom_convexM        r   c                      y)zIs the atom concave?
        Fr1   r"   s    r   is_atom_concavez condition_number.is_atom_concaveR   r5   r   c                      y)z!Is the atom quasiconvex?
        Tr1   r"   s    r   is_atom_quasiconvexz$condition_number.is_atom_quasiconvexW   s     r   c                      y)z;Is the composition non-decreasing in argument idx?
        Fr1   r   idxs     r   is_incrzcondition_number.is_incr\   r5   r   c                      y)z;Is the composition non-increasing in argument idx?
        Fr1   r;   s     r   is_decrzcondition_number.is_decra   r5   r   )r
   N)__name__
__module____qualname____doc__r   r   r   r   r#   r&   r,   r   intr/   boolr2   r4   r7   r9   r=   r?   __classcell__)r   s   @r   r	   r	      s    2%Cj) C
"sCx 
dDj 1 
 
 
T 
d 
d r   r	   N)rC   typingr   r   scipyr   r   cvxpy.atoms.atomr   cvxpy.constraints.constraintr   r	   r1   r   r   <module>rK      s&      ! 3Lt Lr   