
    bi                         d Z ddlZddlmZ ddlmZmZmZm	Z	 ddl
mc 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.
    N)reduce)AnyIterableListTuple)AffAtom)
Constraint)
Expressionc                        e Zd ZdZdee   ddf fdZdeedf   fdZ	dede
e   fd	Zdefd
Zdee   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ddZ	 ddeedf   deej.                  e
e   f   fdZ xZS )AddExpressionz*The sum of any number of expressions.
    
arg_groupsreturnNc                     t        t        | 
  |  g | _        |D ]&  }| xj                  | j	                  |      z  c_        ( y N)superr   __init__argsexpand_args)selfr   group	__class__s      V/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/atoms/affine/add_expr.pyr   zAddExpression.__init__    sA    mT+Z8	 	1EII))%00I	1    .c                     t         j                  j                  | j                  D cg c]  }|j                   c}      S c c}w )z8Returns the (row, col) shape of the expression.
        )ushape
sum_shapesr   )r   args     r   shape_from_argszAddExpression.shape_from_args&   s/     ww!!		"B399"BCC"Bs   Aexprc                 @    t        |t              r|j                  S |gS )zHHelper function to extract the arguments from an AddExpression.
        )
isinstancer   r   )r   r    s     r   r   zAddExpression.expand_args+   s     dM*996Mr   c                     t        | j                  d         }t        dt        | j                              D ]   }|dt        | j                  |         z   z  }" |S )Nr      z + )strr   rangelen)r   resultis      r   namezAddExpression.name3   sS    TYYq\"q#dii.) 	0Aec$))A,///F	0r   valuesc                 6    t        t        j                  |      S r   )r   opadd)r   r+   s     r   numericzAddExpression.numeric9   s    bfff%%r   c                      y)z$Is the atom log-log convex?
        T r   s    r   is_atom_log_log_convexz$AddExpression.is_atom_log_log_convex<   s     r   c                      y)z%Is the atom log-log concave?
        Fr1   r2   s    r   is_atom_log_log_concavez%AddExpression.is_atom_log_log_concaveA   s     r   c                     t        d | j                  D              }| j                  d   | j                  d   k(  xr |S )z%Is the expression symmetric?
        c              3   <   K   | ]  }|j                           y wr   )is_symmetric.0r   s     r   	<genexpr>z-AddExpression.is_symmetric.<locals>.<genexpr>I        @s((*@   r   r$   allr   r   )r   	symm_argss     r   r8   zAddExpression.is_symmetricF   8     @dii@@	zz!}

1-;);r   c                     t        d | j                  D              }| j                  d   | j                  d   k(  xr |S )z%Is the expression Hermitian?
        c              3   <   K   | ]  }|j                           y wr   )is_hermitianr9   s     r   r;   z-AddExpression.is_hermitian.<locals>.<genexpr>O   r<   r=   r   r$   r>   )r   	herm_argss     r   rD   zAddExpression.is_hermitianL   rA   r   c                 x    || g}t        |       j                  t        |             }|j                  |       |S )a*  Returns a shallow copy of the AddExpression atom.

        Parameters
        ----------
        args : list, optional
            The arguments to reconstruct the atom. If args=None, use the
            current args of the atom.

        Returns
        -------
        AddExpression atom
        )type__new__r   )r   r   
id_objectscopys       r   rJ   zAddExpression.copyT   s;     <
 6DDz!!$t*-dr   r   c                     t        |      D ]D  \  }}|j                  |k7  st        j                  |      s,t        j                  ||      ||<   F t        j
                  |      g fS )az  Sum the linear expressions.

        Parameters
        ----------
        arg_objs : list
            LinExpr for each argument.
        shape : tuple
            The shape of the resulting expression.
        data :
            Additional data required by the atom.

        Returns
        -------
        tuple
            (LinOp for objective, list of constraints)
        )	enumerater   lu	is_scalarpromotesum_expr)r   arg_objsr   datar)   r   s         r   graph_implementationz"AddExpression.graph_implementationk   s]    &  ) 	5FAsyyE!bll3&7 jje4	5 H%r**r   )NN)r   r   r   )__name__
__module____qualname____doc__r   r
   r   r   intr   r   r   r%   r*   r   r/   boolr3   r5   r8   rD   rJ   loLinOpr	   rS   __classcell__)r   s   @r   r   r      s    18J#7 1D 1DsCx D

 tJ/? c &hsm & & 
 
<d <<d <0 6:+$S#X+	rxxj))	*+r   r   )rW   operatorr-   	functoolsr   typingr   r   r   r   cvxpy.lin_ops.lin_oplin_opslin_oprZ   cvxpy.lin_ops.lin_utils	lin_utilsrM   cvxpy.utilities	utilitiesr   cvxpy.atoms.affine.affine_atomr   cvxpy.constraints.constraintr	   cvxpy.expressions.expressionr
   r   r1   r   r   <module>rj      s>      - - ! ! $ $  2 3 3e+G e+r   