
    bi
                     V    d Z ddlmZ ddl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.
    )TupleN)	logsumexp)Atom)AxisAtomc                        e Zd ZdZddeddf fdZej                  d        Zd Z	d Z
deeef   fd	Zdefd
ZdefdZdefdZdefdZ xZS )log_sum_expz :math:`\log\sum_i e^{x_i}`

    Nkeepdimsreturnc                 2    t         t        |   |||       y )Naxisr	   )superr   __init__)selfxr   r	   	__class__s       R/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/atoms/log_sum_exp.pyr   zlog_sum_exp.__init__   s    k4)!$)J    c                 L    t        |d   | j                  | j                        S )z<Evaluates e^x elementwise, sums, and takes the log.
        r   r   )r   r   r	   r   valuess     r   numericzlog_sum_exp.numeric"   s     T]]KKr   c                 $    | j                  |      S )a+  Gives the (sub/super)gradient of the atom w.r.t. each argument.

        Matrix expressions are vectorized, so the gradient is a matrix.

        Args:
            values: A list of numeric values for the arguments.

        Returns:
            A list of SciPy CSC sparse matrices or None.
        )
_axis_gradr   s     r   _gradzlog_sum_exp._grad(   s     v&&r   c                 |    t        j                  t        |dd            }t        j                  |      }||z  }|S )a  Gives the (sub/super)gradient of the atom w.r.t. a column argument.

        Matrix expressions are vectorized, so the gradient is a matrix.

        Args:
            value: A numeric value for a column.

        Returns:
            A NumPy ndarray or None.
        NTr   )npexpr   )r   valuedenomnomDs        r   _column_gradzlog_sum_exp._column_grad5   s6     yTDABffUmIr   c                 @    | j                   d   j                         dfS )zCReturns sign (is positive, is negative) of the expression.
        r   F)args	is_nonnegr   s    r   sign_from_argszlog_sum_exp.sign_from_argsE   s      		!&&(%00r   c                      y)zIs the atom convex?
        T r'   s    r   is_atom_convexzlog_sum_exp.is_atom_convexK        r   c                      y)zIs the atom concave?
        Fr*   r'   s    r   is_atom_concavezlog_sum_exp.is_atom_concaveP        r   c                      y)z;Is the composition non-decreasing in argument idx?
        Tr*   r   idxs     r   is_incrzlog_sum_exp.is_incrU   r,   r   c                      y)z;Is the composition non-increasing in argument idx?
        Fr*   r1   s     r   is_decrzlog_sum_exp.is_decrZ   r/   r   )NF)__name__
__module____qualname____doc__boolr   r   numpy_numericr   r   r#   r   r(   r+   r.   r3   r5   __classcell__)r   s   @r   r   r      s    Kt K K 
L L
' 1dDj 1 1 
 
d 
d r   r   )r9   typingr   numpyr   scipy.specialr   cvxpy.atoms.atomr   cvxpy.atoms.axis_atomr   r   r*   r   r   <module>rB      s)       # ! *C( Cr   