
    bi                     h    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dded	efd
Zy)a,  
Copyright 2018 Akshay Agrawal

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)hstack)AxisAtomc                        e Zd ZdZddeddf f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defdZdefdZd Zd Zd Z xZS )Proda  Multiply the entries of an expression.

    The semantics of this atom are the same as np.prod.

    This atom is log-log affine, but it is neither convex nor concave.

    Parameters
    ----------
    expr : Expression
        The expression to multiply the entries of.
    axis : int
        The axis along which to sum.
    keepdims : bool
        Whether to drop dimensions after summing.
    Nkeepdimsreturnc                 2    t         t        |   |||       y )Naxisr   )superr   __init__)selfexprr   r   	__class__s       K/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/atoms/prod.pyr   zProd.__init__+   s    dD"4dX"F    c                 @    | j                   d   j                         ryy)zCReturns sign (is positive, is negative) of the expression.
        r   )TF)FFargs	is_nonnegr   s    r   sign_from_argszProd.sign_from_args.   s     99Q<!!# r   c                      y)zIs the atom convex?
        F r   s    r   is_atom_convexzProd.is_atom_convex5        r   c                      y)zIs the atom concave?
        Fr   r   s    r   is_atom_concavezProd.is_atom_concave:   r   r   c                      y)z$Is the atom log-log convex?
        Tr   r   s    r   is_atom_log_log_convexzProd.is_atom_log_log_convex?        r   c                      y)z%Is the atom log-log concave?
        Tr   r   s    r   is_atom_log_log_concavezProd.is_atom_log_log_concaveD   r"   r   c                 <    | j                   d   j                         S )z;Is the composition non-decreasing in argument idx?
        r   r   r   idxs     r   is_incrzProd.is_incrI   s     yy|%%''r   c                      y)z;Is the composition non-increasing in argument idx?
        Fr   r&   s     r   is_decrzProd.is_decrN   r   r   c                    t        j                  |d         r|d   }| j                  q|j                  |j                  d   |j                  d   z  k(  r|j
                  }n!t        j                  d|j                        }t        j                  |      }|S | j                  dv r|j                  | j                        |j                  | j                     k(  }t        j                  |j                  d| j                  z
     |j                        }| j                  dk(  r	|dd|f   n||ddf   }t        j                  |j                         | j                        ||<   | j                  r-t        j                  || j                        }|S t        d      |S t        j                  |d   | j                  | j                        }|S )	z3Takes the product of the entries of value.
        r   N   )dtype)r   r,   )r   z6cp.prod does not support axis > 1 for sparse matrices.r   )intf	is_sparser   nnzshapedatanpzerosr-   prod_getnnztoarrayr   expand_dimsUserWarning)r   valuessp_matr2   resultmasks         r   numericzProd.numericS   so    >>&)$AYFyy ::a6<<?!BB!;;D88AV\\:D  f$ ~~499~5dii9PP&,,q{";6<<P*.))q.vagfT1Wo!wwt||~DIIFt==^^FDII>F
  ""Z[[  WWVAYTYYOFr   c                 2    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.
        )r3   r5   )r   values     r   _column_gradzProd._column_gradn   s     wwu~%%r   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_grad)r   r:   s     r   _gradz
Prod._grad{   s     v&&r   NF)__name__
__module____qualname____doc__boolr   r   r   r   r   r!   r$   r(   r*   r>   rA   rD   __classcell__)r   s   @r   r   r      s     G$ G4 GdDj 1  
 
 
 
(d (
d 
6&'r   r   r   r	   c                 d    t        | t              rt        t        |             S t        | ||      S )a9  Multiply the entries of an expression.

    The semantics of this atom are the same as np.prod.

    This atom is log-log affine, but it is neither convex nor concave.

    Parameters
    ----------
    expr : Expression or list[Expression, Numeric]
        The expression to multiply the entries of, or a list of Expressions
        and numeric types.
    axis : int
        The axis along which to take the product; ignored if `expr` is a list.
    keepdims : bool
        Whether to drop dimensions after taking the product; ignored if `expr`
        is a list.
    )
isinstancelistr   r   )r   r   r   s      r   r5   r5      s,    $ $F4L!!D$))r   rE   )rI   typingr   numpyr3   cvxpy.interface	interfacer.   cvxpy.atoms.affine.hstackr   cvxpy.atoms.axis_atomr   r   rJ   r5   r   r   r   <module>rU      s=        , *l'8 l'^*D *T *r   