
    bi                        d Z ddlmZ ddlmZmZmZmZ ddlm	Z
 ddlmc 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.
    )annotations)AnyIterableOptionalTupleN)settings)
Constraint)
Expression)Leafc                       e Zd ZdZ	 	 d	 	 	 	 	 	 	 d fdZddZddZedd       ZddZ	ddZ
ddZdd	Zdd
ZddZ xZS )Variablez(The optimization variables in a problem.c                F   |t        j                         | _        n|| _        |%dt        j                  | j                  fz  | _        n&t        |t              r|| _        nt        d|z        d | _	        d | _
        d | _        d | _        t        t        | >  |fi | y )Nz%s%dz"Variable name %s must be a string.)luget_idids
VAR_PREFIX_name
isinstancestr	TypeError_variable_with_attributes_valuedeltagradientsuperr   __init__)selfshapenamevar_idkwargs	__class__s        U/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/expressions/variable.pyr   zVariable.__init__    s     >iikDGDG<1<<"99DJc"DJ@4GHH:>&
h&u77    c                    | j                   S )zThe name of the variable.)r   r   s    r$   r    zVariable.name5   s    zzr%   c                     y)NF r'   s    r$   is_constantzVariable.is_constant9   s    r%   c                H    | t        j                  | j                  d      iS )zGives the (sub/super)gradient of the expression w.r.t. each variable.

        Matrix expressions are vectorized, so the gradient is a matrix.
        csc)format)sp	eye_arraysizer'   s    r$   gradzVariable.grad<   s     bll499U;<<r%   c                    | gS )zReturns itself as a variable.r)   r'   s    r$   	variableszVariable.variablesE   s	    vr%   c                ^    t        j                  | j                  | j                        }|g fS )z/Returns the graph implementation of the object.)r   
create_varr   r   )r   objs     r$   canonicalizezVariable.canonicalizeI   s$    mmDJJ0Ryr%   c                    | j                   duS )zETrue iff variable generated when lowering a variable with attributes.Nr   r'   s    r$   attributes_were_loweredz Variable.attributes_were_loweredN   s    --T99r%   c                .    |j                   sJ || _        y )N)
attributesr   )r   variables     r$   set_variable_of_provenancez#Variable.set_variable_of_provenanceR   s    """")1&r%   c                    | j                   S )zJReturns a variable with attributes from which this variable was generated.r9   r'   s    r$   variable_of_provenancezVariable.variable_of_provenanceV   s    ---r%   c                h    | j                         }d| j                   d| j                          | dS )z String to recreate the variable.z	Variable(z, ))_get_attr_strr   __str__)r   attr_strs     r$   __repr__zVariable.__repr__Z   s4    %%'4::,b(8
!DDr%   )r)   NN)r   zint | Iterable[int]r    z
str | Noner!   z
int | Noner"   r   )returnr   )rG   bool)rG   z&Optional[dict[Variable, sp.csc_array]])rG   zlist[Variable])rG   z#Tuple[Expression, list[Constraint]])r=   r   rG   None)rG   zOptional[Variable])__name__
__module____qualname____doc__r   r    r*   propertyr1   r3   r7   r:   r>   r@   rF   __classcell__)r#   s   @r$   r   r      sr    2 CG!8(85?88-08* = =
:2.Er%   r   )rM   
__future__r   typingr   r   r   r   scipy.sparsesparser.   cvxpy.lin_ops.lin_utilslin_ops	lin_utilsr   cvxpyr   r   cvxpy.constraints.constraintr	   cvxpy.expressions.expressionr
   cvxpy.expressions.leafr   r   r)   r%   r$   <module>r[      s:    # 1 1  $ $  3 3 '@Et @Er%   