
    bi~                    p    d 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Zdd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.
    )annotationsN)settings)Leaf)scopesc                    t        j                         5  | j                          xr | j                         cddd       S # 1 sw Y   yxY w)zCReturns true if expression is parameters-affine (and variable-free)N)r   	dpp_scope	variables	is_affineexprs    `/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/expressions/constants/parameter.pyis_param_affiner      s<    				 9>>##8(89 9 9s   #AAc                $    | j                          S )z/Returns true if expression is not parametrized.)
parametersr   s    r   is_param_freer      s           c                  t     e Zd ZdZdZ	 	 d	 	 	 	 	 d fdZd ZddZddZe	d        Z
ddZd	 Zdd
Z xZS )	Parametera  Parameters in optimization problems.

    Parameters are constant expressions whose value may be specified
    after problem creation. The only way to modify a problem after its
    creation is through parameters. For example, you might choose to declare
    the hyper-parameters of a machine learning model to be Parameter objects;
    more generally, Parameters are useful for computing trade-off curves.
    r   c                   |t        j                         | _        n|| _        |$t        j                   | j                   | _        n|| _        d | _        d | _        d | _        t        t        | .  ||fi | d| _        y )NT)luget_ididsPARAM_PREFIX_name_valuedeltagradientsuperr   __init___is_constant)selfshapenamevaluer   kwargs	__class__s         r   r    zParameter.__init__.   sv     :iikDGDG<NN+DGG95DJDJ
i'u?? r   c                t    | j                   | j                  | j                  | j                  | j                  gS )zLReturns info needed to reconstruct the expression besides the args.
        )r#   r   r%   r   
attributesr"   s    r   get_datazParameter.get_dataA   s)     

DJJ

DGGT__MMr   c                    | j                   S )N)r   r*   s    r   r$   zParameter.nameF   s    zzr   c                .    t        j                         ryy)NFT)r   dpp_scope_activer*   s    r   is_constantzParameter.is_constantI   s    ""$r   c                    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.

        Returns:
            A map of variable to SciPy CSC sparse matrix or None.
         r*   s    r   gradzParameter.gradN   s	     	r   c                    | gS )z'Returns itself as a parameter.
        r1   r*   s    r   r   zParameter.parametersY   s     vr   c                ^    t        j                  | j                  | j                        }|g fS )zReturns the graph implementation of the object.

        Returns:
            A tuple of (affine expression, [constraints]).
        )r   create_paramr#   r   )r"   objs     r   canonicalizezParameter.canonicalize^   s&     oodjj$''2Ryr   c                    | j                         }t        |      dkD  rd| j                  |dS d| j                  dS )z'String to recreate the object.
        r   z
Parameter())_get_attr_strlenr#   )r"   attr_strs     r   __repr__zParameter.__repr__g   sA     %%'x=1(,

H==  '+jj22r   )r1   NNN)r#   zint | tuple[int, ...]r$   z
str | NonereturnNone)r>   strr>   bool)r>   zlist[Parameter])__name__
__module____qualname____doc__PARAM_COUNTr    r+   r$   r/   propertyr2   r   r7   r=   __classcell__)r'   s   @r   r   r   #   sk     K QU!*!7A! 
!&N

  
3r   r   rA   )rF   
__future__r   cvxpy.lin_ops.lin_utilslin_ops	lin_utilsr   cvxpyr   r   cvxpy.expressions.leafr   cvxpy.utilitiesr   r   r   r   r1   r   r   <module>rQ      s6    # $ $  ' "9!
K3 K3r   