
    bi                     J    d Z ddl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.
    N)linalg)
lambda_max)sum_largestc                   R     e Zd ZdZdZd	 fdZd	dZd Zd Zd Z	e
d        Z xZS )
lambda_sum_largestz&Sum of the largest k eigenvalues.
    Tc                 :    || _         t        t        |   |       y )N)ksuperr   __init__)selfXr	   	__class__s      Y/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/atoms/lambda_sum_largest.pyr   zlambda_sum_largest.__init__   s     $03    c                     | j                   d   }|j                  dk(  r|j                  d   |j                  d   k7  rt        d      | j                  dk  rt        d      y)z.Verify that the argument A is square.
        r         z'First argument must be a square matrix.z*Second argument must be a positive number.N)argsndimshape
ValueErrorr	   )r   r   s     r   validate_argumentsz%lambda_sum_largest.validate_arguments!   s[     IIaLvv{aggajAGGAJ6FGGVVq[IJJ r   c                 r    t        j                  |d         }t        || j                        j                  S )zTReturns the largest eigenvalue of A.

        Requires that A be symmetric.
        r   )LAeigvalshr   r	   value)r   valueseigss      r   numericzlambda_sum_largest.numeric*   s-    
 {{6!9%4(...r   c                     | j                   gS )z!Returns the parameter k.
        )r	   )r   s    r   get_datazlambda_sum_largest.get_data2   s     xr   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lambda_sum_largest._grad7   s     "##r   c                 b   t        j                  | j                  d   j                  | j                  d   j                  j                  j                               st        d      t        | j                         D cg c]  }|j                  d u  c}      ry | j                         S c c}w )Nr   z)Input matrix was not Hermitian/symmetric.)
npallcloser   r   Tconjr   any
parameters_value_impl)r   ps     r   r   zlambda_sum_largest.valueD   s    {{499Q<--tyy|/A/A/C/C/H/H/JKHII):;A4;<!! <s   ?B,)returnN)__name__
__module____qualname____doc___allow_complexr   r   r   r!   r$   propertyr   __classcell__)r   s   @r   r   r      s;    N4K/
$ " "r   r   )r2   numpyr&   scipyr   r   cvxpy.atoms.lambda_maxr   cvxpy.atoms.sum_largestr   r    r   r   <module>r;      s$       - /2" 2"r   