
    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, the CVXPY authors

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)Atom)cvxtypesc                        e Zd ZdZd fdZd ZdefdZd fdZde	e
df   fdZd	 Zde	eef   fd
ZdefdZdefdZd ZdefdZdefdZdefdZdefdZddZ xZS )gmatmula  Geometric matrix multiplication; :math:`A \mathbin{\diamond} X`.

    For :math:`A \in \mathbf{R}^{m \times n}` and
    :math:`X \in \mathbf{R}^{n \times p}_{++}`, this atom represents

    .. math::

        \left[\begin{array}{ccc}
         \prod_{j=1}^n X_{j1}^{A_{1j}} & \cdots & \prod_{j=1}^n X_{pj}^{A_{1j}} \\
         \vdots &  & \vdots \\
         \prod_{j=1}^n X_{j1}^{A_{mj}} & \cdots & \prod_{j=1}^n X_{pj}^{A_{mj}}
        \end{array}\right]

    This atom is log-log affine (in :math:`X`).

    Parameters
    ----------
    A : cvxpy.Expression
        A constant matrix.
    X : cvxpy.Expression
        A positive matrix.
    returnc                 `    t        j                  |      | _        t        t        |   |       y N)r   cast_to_constAsuperr   __init__)selfr   X	__class__s      N/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/atoms/gmatmul.pyr   zgmatmul.__init__1   s&     ##A&gt%a(    c                     t        j                  |d         }t        j                  | j                  j                  |z        S )z)Geometric matrix multiplication.
        r   )nplogexpr   value)r   valueslogXs      r   numericzgmatmul.numeric8   s2     vvfQi vvdffllT)**r   c                 n    | j                   j                  d| j                  d| j                  d   dS )N(z, r   ))r   __name__r   argsr   s    r   namezgmatmul.name>   s+    #~~66#vv#yy|- 	-r   c                 ^   t         t        |           | j                  j	                         st        d      | j                  j                         r3t        | j                  t        j                               st        d      | j                  d   j                         st        d      y)z6Raises an error if the arguments are invalid.
        z*gmatmul(A, X) requires that A be constant.z;gmatmul(A, X) requires that A be a Constant or a Parameter.r   z*gmatmul(A, X) requires that X be positive.N)r   r   validate_argumentsr   is_constant
ValueError
parameters
isinstancer   	parameterr    is_pos)r   r   s    r   r$   zgmatmul.validate_argumentsC   s     	gt/1vv!!#<  66z$&&(:L:L:N'OM  yy|""$<  %r   .c                     t         j                  j                  | j                  j                  | j                  d   j                        S )z8Returns the (row, col) shape of the expression.
        r   )ushape
mul_shapesr   r    r!   s    r   shape_from_argszgmatmul.shape_from_argsT   s1     ww!!$&&,,		!0B0BCCr   c                     | j                   gS )zLReturns info needed to reconstruct the expression besides the args.
        )r   r!   s    r   get_datazgmatmul.get_dataY   s     xr   c                      y)zCReturns sign (is positive, is negative) of the expression.
        )TF r!   s    r   sign_from_argszgmatmul.sign_from_args^   s     r   c                      y)zIs the atom convex?
        Fr3   r!   s    r   is_atom_convexzgmatmul.is_atom_convexc        r   c                      y)zIs the atom concave?
        Fr3   r!   s    r   is_atom_concavezgmatmul.is_atom_concaveh   r7   r   c                 r    | j                   d   j                         | j                  j                         z   S )Nr   )r    r'   r   r!   s    r   r'   zgmatmul.parametersm   s+    yy|&&(466+<+<+>>>r   c                     t         j                  j                         r>| j                  d   }| j                  }|j                         xr |j                          S y)z$Is the atom log-log convex?
        r   T)r,   scopesdpp_scope_activer    r   r'   )r   r   r   s      r   is_atom_log_log_convexzgmatmul.is_atom_log_log_convexq   sI     88$$& 		!AA91<<>::r   c                 "    | j                         S )z%Is the atom log-log concave?
        )r>   r!   s    r   is_atom_log_log_concavezgmatmul.is_atom_log_log_concave   s     **,,r   c                 6    | j                   j                         S )z;Is the composition non-decreasing in argument idx?
        )r   	is_nonnegr   idxs     r   is_incrzgmatmul.is_incr        vv!!r   c                 6    | j                   j                         S )z;Is the composition non-increasing in argument idx?
        )r   	is_nonposrC   s     r   is_decrzgmatmul.is_decr   rF   r   c                      y r
   r3   )r   r   s     r   _gradzgmatmul._grad   s    r   )r   N)r   
__module____qualname____doc__r   r   strr"   r$   r   intr/   r1   boolr4   r6   r9   r'   r>   r@   rE   rI   rK   __classcell__)r   s   @r   r   r      s    ,)+-c -
"DsCx D

dDj 1 
 
 
? ,- -
"d "
"d "
r   r   )rN   typingr   numpyr   cvxpy.utilities	utilitiesr,   cvxpy.atoms.atomr   cvxpy.expressionsr   r   r3   r   r   <module>rY      s)        ! &}d }r   