
    bi                     `    d Z ddlmZmZ ddlZddlmc mZ	 ddl
mZ ddlmZ  G d de      Zy)a,  
Copyright 2017 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)
Constraint)
Expressionc                   J    e Zd ZdZddee   deddf fdZej                  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de
fdZde
fdZde
fdZde
fdZdee   fdZedeedf   fd       Zddede
fdZdefdZdee   fdZedefd       Zed        Z xZS )	indicatora%  An expression representing the convex function I(constraints) = 0
       if constraints hold, +infty otherwise.

    Parameters
    ----------
    constraints : list
       A list of constraint objects.
    err_tol:
       A numeric tolerance for determining whether the constraints hold.
    constraintserr_tolreturnNc                 F    || _         || _        t        t        |           y )N)argsr
   superr   __init__)selfr	   r
   	__class__s      U/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/transforms/indicator.pyr   zindicator.__init__&   s    	i')    c                     t        | j                  D cg c]  }|j                   c}g       }t        |D cg c]  }|j                          c}      S c c}w c c}w )zIThe Indicator is constant if all constraints have constant args.
        )sumr   allis_constant)r   call_argsargs       r   r   zindicator.is_constant+   sH     		212B7:#COO%:;; 3:s
   AAc                      y)z"Is the expression convex?
        T r   s    r   	is_convexzindicator.is_convex2        r   c                      y)z#Is the expression concave?
        Fr   r   s    r   
is_concavezindicator.is_concave7        r   c                      yNFr   r   s    r   is_log_log_convexzindicator.is_log_log_convex<       r   c                      yr$   r   r   s    r   is_log_log_concavezindicator.is_log_log_concave?   r&   r   c                      y)z$Is the expression positive?
        Tr   r   s    r   	is_nonnegzindicator.is_nonnegB   r   r   c                      y)z$Is the expression negative?
        Fr   r   s    r   	is_nonposzindicator.is_nonposG   r"   r   c                      y)zIs the Leaf imaginary?
        Fr   r   s    r   is_imagzindicator.is_imagL   r"   r   c                      y)z$Is the Leaf complex valued?
        Fr   r   s    r   
is_complexzindicator.is_complexQ   r"   r   c                     | j                   gS )zLReturns info needed to reconstruct the expression besides the args.
        )r
   r   s    r   get_datazindicator.get_dataV   s     ~r   .c                      y)z=Returns the (row, col) dimensions of the expression.
        r   r   r   s    r   shapezindicator.shape[   s     r   contextc                      y)zBThe expression is a disciplined parameterized expression.
        Fr   )r   r5   s     r   is_dppzindicator.is_dppa   r"   r   c                 "    d| j                    dS )z=Returns the string representation of the expression.
        z
Indicator()r   r   s    r   namezindicator.namef   s     DII;a((r   c                     | j                   S )znA list of constraints describing the closure of the region
           where the expression is finite.
        r:   r   s    r   domainzindicator.domaink   s     yyr   c                 b     t         fd j                  D              ryt        j                  S )zoReturns the numeric value of the expression.

        Returns:
            A numpy matrix or a scalar.
        c              3   V   K   | ]   }|j                  j                          " yw))	toleranceN)valuer
   ).0consr   s     r   	<genexpr>z"indicator.value.<locals>.<genexpr>x   s      HdtzzDLLz1Hs   &)g        )r   r   npinfr   s   `r   rA   zindicator.valueq   s#     HdiiHH66Mr   c                     t               )a-  Gives the (sub/super)gradient of the expression w.r.t. each variable.

        Matrix expressions are vectorized, so the gradient is a matrix.
        None indicates variable values unknown or outside domain.

        Returns:
            A map of variable to SciPy CSC sparse matrix or None.
        )NotImplementedErrorr   s    r   gradzindicator.grad}   s     "##r   )gMbP?)dcp) __name__
__module____qualname____doc__r   r   floatr   perfcompute_onceboolr   r   r!   r%   r(   r*   r,   r.   r0   r2   propertyr   intr4   strr7   r;   r=   rA   rI   __classcell__)r   s   @r   r   r      s;   	*D$4 *u *PT *
 
<T < <4 
D 
4 D 4 
4 
 
D 
$u+ 
 uS#X  
c d 
)c )
Z(  	u 	 	 
$ 
$r   r   )rN   typingr   r   numpyrE   !cvxpy.utilities.performance_utils	utilitiesperformance_utilsrP   cvxpy.constraints.constraintr   cvxpy.expressions.expressionr   r   r   r   r   <module>r^      s,       0 0 3 3n$
 n$r   