
    biB	                     h    d Z ddlmZ ddlZddlm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 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.
    )TupleN)Atomc                   v     e Zd ZdZdeedf   fdZd
 fdZdefdZ	e
d        Ze
deedf   fd	       Z xZS )Elementwisez, Abstract base class for elementwise atoms. return.c                     t         j                  j                  | j                  D cg c]  }|j                   c}      S c c}w )z7Shape is the same as the sum of the arguments.
        )ushape
sum_shapesargs)selfargs     ^/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/atoms/elementwise/elementwise.pyshape_from_argszElementwise.shape_from_args   s/     ww!!		"B399"BCC"Bs   Ac                     t         j                  j                  | j                  D cg c]  }|j                   c}       t        t
        |           yc c}w )zU
        Verify that all the shapes are the same
        or can be promoted.
        N)r	   r
   r   r   superr   validate_arguments)r   r   	__class__s     r   r   zElementwise.validate_arguments#   s<    
 	
;#CII;<k435 <s   Ac                     t        d | j                  D              }| j                  d   | j                  d   k(  xr |S )z%Is the expression symmetric?
        c              3   <   K   | ]  }|j                           y w)N)is_symmetric).0r   s     r   	<genexpr>z+Elementwise.is_symmetric.<locals>.<genexpr>.   s     @s((*@s   r      )allr   r
   )r   	symm_argss     r   r   zElementwise.is_symmetric+   s8     @dii@@	zz!}

1-;);    c                     t        j                  |       s| j                  d      } t        j                  t        j
                  |       dgf||f      j                         S )zConverts elementwise gradient into a diagonal matrix for Atom._grad()

        Args:
            value: A scalar or NumPy matrix.

        Returns:
            A SciPy CSC sparse matrix.
        F)orderr   )r
   )npisscalarravelsp	dia_array
atleast_1dtocsc)valuerowscolss      r   elemwise_grad_to_diagz!Elementwise.elemwise_grad_to_diag1   sN     {{5!KKcK*E||R]]51A37d|LRRTTr   r
   c                 P    | j                   |k7  rt        j                  | |      S | S )a  Promotes the lin op if necessary.

        Parameters
        ----------
        arg : LinOp
            LinOp to promote.
        shape : tuple
            The shape desired.

        Returns
        -------
        tuple
            Promoted LinOp.
        )r
   lupromote)r   r
   s     r   _promotezElementwise._promote?   s&      99::c5))Jr   )r   N)__name__
__module____qualname____doc__r   intr   r   boolr   staticmethodr+   r/   __classcell__)r   s   @r   r   r      sf    6DsCx D
6<d < U U U38_  r   r   )r3   typingr   numpyr!   scipy.sparsesparser$   cvxpy.lin_ops.lin_utilslin_ops	lin_utilsr-   cvxpy.utilities	utilitiesr	   cvxpy.atoms.atomr   r    r   r   <module>rC      s-        $ $  !7$ 7r   