
    bix                     n   d Z ddlZddlZddlmZ ddlmZmZmZm	Z	 ddl
ZddlZddlmZ ddl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mZmZ ddlm Z  ddlm!Z! dd	l"m#Z# d
 Z$da%dZ&dZ'dZ(dZ)dZ*ejV                  d ejX                  d ejZ                  d ej\                  d ej^                  d ej`                  d ejb                  d ejd                  d ejf                  d ejh                  d ejj                  d ejl                  d ejn                  d iZ8dZ9 G d d ejt                        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wraps)ListLiteralOptionalTuple)error)PSDEquality
Inequality)cvxtypes)scopes)size_from_shapec                 .     t                fd       }|S )zCasts the second argument of a binary operator as an Expression.

    Args:
        binary_op: A binary operator in the Expression class.

    Returns:
        A wrapped binary operator that can handle non-Expression arguments.
    c                 8    | j                  |      } | |      S )zLA wrapped binary operator that can handle non-Expression arguments.
        )cast_to_const)selfother	binary_ops     W/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/expressions/expression.pycast_opz_cast_other.<locals>.cast_op.   s"     ""5)u%%    r   )r   r   s   ` r   _cast_otherr   $   s#     9& &
 Nr      ak  
This use of ``*`` has resulted in matrix multiplication.
Using ``*`` for matrix multiplication has been deprecated since CVXPY 1.1.
    Use ``*`` for matrix-scalar and vector-scalar multiplication.
    Use ``@`` for matrix-matrix and matrix-vector multiplication.
    Use ``multiply`` for elementwise multiplication.
This code path has been hit %s times so far.
z
You're calling a NumPy function on a CVXPY expression. This is prone to causing
errors or code that doesn't behave as expected. Consider using one of the
functions documented here: https://www.cvxpy.org/tutorial/functions/index.html
z
You're trying to mutate a CVXPY expression inplace. This is prone to errors or
code that doesn't behave as expected. Consider alternatives. For example, replace
    x += 1
with
    x = x + 1
z
You're calling the built-in abs function on a CVXPY expression. This is not
supported. Consider using the abs function provided by CVXPY.
a"  
    You didn't specify the order of the FUNC_NAME expression. The default order
    used in CVXPY is Fortran ('F') order. This default will change to match NumPy's
    default order ('C') in a future version of CVXPY.
    To suppress this warning, please specify the order explicitly.
    c                 $    | j                  |      S N)__radd__r   as     r   <lambda>r    _   s    a 0 r   c                 $    | j                  |      S r   )__rsub__r   s     r   r    r    `       T]]1%5 r   c                 $    | j                  |      S r   )__rmul__r   s     r   r    r    a   r#   r   c                 $    | j                  |      S r   )__rdiv__r   s     r   r    r    b   s    4==#3 r   c                 $    | j                  |      S r   )__rmatmul__r   s     r   r    r    c   s    4#3#3A#6 r   c                 $    | j                  |      S r   )__rpow__r   s     r   r    r    d   s    $--"2 r   c                 $    | j                  |      S r   )__rlshift__r   s     r   r    r    e   s    t'7'7': r   c                 $    | j                  |      S r   )__rrshift__r   s     r   r    r    f   s    (8(8(; r   c                 $    | j                  |      S r   )__eq__r   s     r   r    r    g   s    $++a. r   c                 $    | j                  |      S r   )__ge__r   s     r   r    r    j   s    t{{1~ r   c                 $    | j                  |      S r   )__le__r   s     r   r    r    k   s    $++a. r   c                 $    | j                  |      S r   )__gt__r   s     r   r    r    l   s    Q r   c                 $    | j                  |      S r   )__lt__r   s     r   r    r    m   s    DKKN r   z Expression | np.typing.ArrayLikec                      e Zd ZdZdZeej                  dee	j                     fd              Zdee	j                     fdZeej                  d               Zeej                  d               ZdefdZdefd	Zej                  defd
       Zed        Zedee   fd       Zedefd       Zedefd       Zej2                  defd       Zej2                  defd       Zej                  defd       Zej                  defd       Zej2                  dqdedefd       ZdefdZ ej2                  defd       Z!ej                  defd       Z"ej                  defd       Z#dqdedefdZ$ej                  drdedefd       Z%defdZ&defdZ'defdZ(ej2                  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efd&Z/defd'Z0defd(Z1defd)Z2edefd*       Z3ej2                  defd+       Z4ej                  defd,       Z5ej                  defd-       Z6eej                  de7e8d.f   fd/              Z9defd0Z:eej                  defd1              Z;ej                  defd2       Z<ede8fd3       Z=ede8fd4       Z>dsd6e?d7   fd8Z@defd9ZAdefd:ZBdefd;ZCdtd<ZDedtd=       ZEedtd>       ZFd?eGdd fd@ZHdAeGdd fdBZIeJdtdC       ZKeJdudD       ZLeJdvdE       ZMeNdFeOdd fdG       ZPeNdFeOdd fdH       ZQeNdFeOdd fdI       ZReNdFeOdd fdJ       ZSeNdFeOdd fdK       ZTeNdFeOdd fdL       ZUeNdFeOdd fdM       ZVeNdFeOdd fdN       ZWeNdFeOdd fdO       ZXeNdFeOdd fdP       ZYeNdFeOdd fdQ       ZZeNdFeOdd fdR       Z[dtdSZ\eNdFeOde]fdT       Z^eNdFeOde]fdU       Z_eNdFeOde]fdV       Z`eNdFeOde]fdW       Zade8fdXZbeNdFeOdecfdY       ZdeNdFeOdeefdZ       ZfdFeOfd[ZgeNdFeOdeefd\       ZhdFeOfd]Zid^ Zjd_ Zkdtd`ZldtdaZmdwdtdcZndsddddtdeZodsddddtdfZpdsddddtdgZqdsddddtdhZrdsddddtdiZsdsd6e?d7   dd fdjZtdsdbddkdtdlZudsddddtdmZvdtdnZwdbdodtdpZxy5)x
ExpressionzA mathematical expression in a convex optimization problem.

    Overloads many operators to allow for convenient creation of compound
    expressions (e.g., the sum of two expressions) and constraints.
    d   returnc                     t               )z6Returns: The numeric value of the expression.
        NotImplementedErrorr   s    r   valuezExpression.value~       
 "##r   c                     | j                   S )z"Implementation of .value.
        )rB   rA   s    r   _value_implzExpression._value_impl   s     zzr   c                     t               )a0  Gives the (sub/super)gradient of the expression w.r.t. each variable.

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

        Returns
        -------
        dict
            A map of variable to SciPy CSC sparse matrix; None if a variable
            value is missing.
        r?   rA   s    r   gradzExpression.grad   s     "##r   c                     t               )zolist : The constraints describing the closure of the region
           where the expression is finite.
        r?   rA   s    r   domainzExpression.domain   s     "##r   c                 "    | j                         S )z>Returns a string showing the mathematical expression.
        )namerA   s    r   __str__zExpression.__str__   s     yy{r   c                 V    d| j                   d| j                  d| j                  dS )z@Returns a string with information about the expression.
        zExpression(z, ))	curvaturesignshaperA   s    r   __repr__zExpression.__repr__   s#     ,0>>+/99+/::7 	7r   c                     t               )z;str : The string representation of the expression.
        r?   rA   s    r   rK   zExpression.name        "##r   c                     | S )zExpression : returns itself. rA   s    r   exprzExpression.expr   s	     r   c                    | j                   t        j                  f| j                  t        j                  f| j
                  t        j                  f| j                  t        j                  f| j                  t        j                  f| j                  t        j                  f| j                  t        j                  f| j                  t        j                   f| j"                  t        j$                  f| j&                  t        j(                  f| j*                  t        j,                  fg}|D cg c]  \  }} |       s| }}}|st        j.                  gS |S c c}}w )z:List : Returns a list of the curvatures of the expression.)is_constantsCONSTANT	is_affineAFFINE	is_convexCONVEX
is_concaveCONCAVEis_log_log_constantLOG_LOG_CONSTANTis_log_log_affineLOG_LOG_AFFINEis_log_log_convexLOG_LOG_CONVEXis_log_log_concaveLOG_LOG_CONCAVEis_quasilinearQUASILINEARis_quasiconvexQUASICONVEXis_quasiconcaveQUASICONCAVEUNKNOWN)r   
curvatures	conditionrO   s       r   rq   zExpression.curvatures   s    qzz*^^QXX&^^QXX&__aii(%%q'9'9:##Q%5%56##Q%5%56$$a&7&78  !--0  !--0!!1>>2

 =GV$8Iy)+iV
VII; Ws   1EEc                    | j                         rt        j                  }|S | j                         rt        j                  }|S | j                         rt        j                  }|S | j                         rt        j                  }|S | j                         rt        j                  }|S | j                         rt        j                  }|S | j                         rt        j                  }|S | j                         rt        j                   }|S | j#                         rt        j$                  }|S | j'                         rt        j(                  }|S t        j*                  }|S )z/str : The curvature of the expression.
        )rY   rZ   r[   r\   r]   r^   r_   r`   ra   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   r   curvature_strs     r   rO   zExpression.curvature   sI    JJM* ) ^^HHM& % ^^HHM" ! __IIM  ##%,,M  ##%,,M  $$&--M    "MMM    "MMM
 	 !!#NNM  IIMr   c                 6   | j                         rt        j                  }|S | j                         rt        j                  }|S | j                         rt        j                  }|S | j                         rt        j                  }|S t        j                  }|S )z7str : The log-log curvature of the expression.
        )
rb   rZ   rc   rd   re   rf   rg   rh   ri   rp   rt   s     r   log_log_curvaturezExpression.log_log_curvature   s     ##%..M  ##%,,M  ##%,,M
 	 $$&--M  IIMr   c                 Z    d| j                   v xs t        d | j                  D              S )z$Is the expression constant?
        r   c              3   <   K   | ]  }|j                           y wr   rY   ).0args     r   	<genexpr>z)Expression.is_constant.<locals>.<genexpr>   s      &4"%COO&4s   )rQ   allargsrA   s    r   rY   zExpression.is_constant   s1     DJJ 4# &4)-&4 #4 	4r   c                 j    | j                         xs" | j                         xr | j                         S z"Is the expression affine?
        )rY   r^   r`   rA   s    r   r\   zExpression.is_affine  s+     !Mdnn&6&L4??;LMr   c                     t               )z"Is the expression convex?
        r?   rA   s    r   r^   zExpression.is_convex  rT   r   c                     t               )z#Is the expression concave?
        r?   rA   s    r   r`   zExpression.is_concave  rT   r   Fdppc                     |r@t        j                         5  | j                         xs | j                         cddd       S | j                         xs | j                         S # 1 sw Y   +xY w)aq  Checks whether the Expression is DCP.

        Parameters
        ----------
        dpp : bool, optional
            If True, enforce the disciplined parametrized programming (DPP)
            ruleset; only relevant when the problem involves Parameters.

        Returns
        -------
        bool
            True if the Expression is DCP, False otherwise.
        N)r   	dpp_scoper^   r`   r   r   s     r   is_dcpzExpression.is_dcp  s\     !!# =~~'<4??+<= =~~44??#44= =   "A%%A.c                    | j                         syt        | t        j                         t        j                         f      r| j                         S | j                  duxr" t        j                  | j                  dkD        S )zFIs the expression log-log constant, ie, elementwise positive?
        FNr   )	rY   
isinstancer   constant	parameteris_posrB   npr~   rA   s    r   rb   zExpression.is_log_log_constant'  se     !dX..0(2D2D2FGH;;= ::T)DbffTZZ!^.DDr   c                 j    | j                         xs" | j                         xr | j                         S r   )rb   rf   rh   rA   s    r   rd   zExpression.is_log_log_affine2  s6     ((* L**,J1H1H1J	Mr   c                     t               )z*Is the expression log-log convex?
        r?   rA   s    r   rf   zExpression.is_log_log_convex9  rT   r   c                     t               )z+Is the expression log-log concave?
        r?   rA   s    r   rh   zExpression.is_log_log_concave?  rT   r   c                     |r@t        j                         5  | j                         xs | j                         cddd       S | j                         xs | j                         S # 1 sw Y   +xY w)zChecks whether the Expression is log-log DCP.

        Returns
        -------
        bool
            True if the Expression is log-log DCP, False otherwise.
        N)r   r   rf   rh   r   s     r   is_dgpzExpression.is_dgpE  si     !!# M--/L43J3J3LM M%%'D4+B+B+DDM Mr   contextc                     t               )zBThe expression is a disciplined parameterized expression.
        r?   )r   r   s     r   is_dppzExpression.is_dppR  rT   r   c                 "    | j                         S r   )r^   rA   s    r   rl   zExpression.is_quasiconvexX  s    ~~r   c                 "    | j                         S r   )r`   rA   s    r   rn   zExpression.is_quasiconcave[  s      r   c                 F    | j                         xr | j                         S r   rl   rn   rA   s    r   rj   zExpression.is_quasilinear^  s    ""$?)=)=)??r   c                 F    | j                         xs | j                         S )zChecks whether the Expression is DQCP.

        Returns
        -------
        bool
            True if the Expression is DQCP, False otherwise.
        r   rA   s    r   is_dqcpzExpression.is_dqcpa  s!     ""$>(<(<(>>r   c                 F    | j                         xr | j                         S )z.Is the expression a Hermitian matrix?
        )is_realis_symmetricrA   s    r   is_hermitianzExpression.is_hermitianl  s     64#4#4#67r   c                      y)z:Is the expression a positive semidefinite matrix?
        FrV   rA   s    r   is_psdzExpression.is_psdq       r   c                      y)z:Is the expression a negative semidefinite matrix?
        FrV   rA   s    r   is_nsdzExpression.is_nsdw  r   r   c                 "    | j                         S )z%Is the expression quadratic?
        rz   rA   s    r   is_quadraticzExpression.is_quadratic}       !!r   c                 "    | j                         S )a  Does the affine head of the expression contain a quadratic term?

        The affine head is all nodes with a path to the root node
        that does not pass through any non-affine atom. If the root node
        is non-affine, then the affine head is the root alone.
        rz   rA   s    r   has_quadratic_termzExpression.has_quadratic_term  s     !!r   c                 "    | j                         S )z%Is the expression symmetric?
        )	is_scalarrA   s    r   r   zExpression.is_symmetric  s     ~~r   c                      y)zJIs this Expression, X, a real matrix that satisfies X + X.T == 0?
        FrV   rA   s    r   is_skew_symmetriczExpression.is_skew_symmetric  s     r   c                 "    | j                         S )z,Is the expression piecewise linear?
        rz   rA   s    r   is_pwlzExpression.is_pwl  r   r   c                 F    | j                         xs | j                         S )z9Is the expression quadratic of piecewise affine?
        )r   r   rA   s    r   is_qpwazExpression.is_qpwa  s       "3dkkm3r   c                     | j                         rt        j                  }|S | j                         rt        j                  }|S | j                         rt        j                  }|S t        j                  }|S )z)str: The sign of the expression.
        )is_zerorZ   ZERO	is_nonnegNONNEG	is_nonposNONPOSrp   )r   sign_strs     r   rP   zExpression.sign  se     <<>vvH  ^^xxH
 	 ^^xxH  yyHr   c                 F    | j                         xr | j                         S )z$Is the expression all zero?
        )r   r   rA   s    r   r   zExpression.is_zero  s     ~~4DNN$44r   c                     t               )z$Is the expression positive?
        r?   rA   s    r   r   zExpression.is_nonneg  rT   r   c                     t               )z$Is the expression negative?
        r?   rA   s    r   r   zExpression.is_nonpos  rT   r   .c                     t               )z+tuple : The expression dimensions.
        r?   rA   s    r   rQ   zExpression.shape  rC   r   c                 $    | j                          S )z!Is the Leaf real valued?
        )
is_complexrA   s    r   r   zExpression.is_real  s     ??$$$r   c                     t               )zIs the Leaf imaginary?
        r?   rA   s    r   is_imagzExpression.is_imag  rC   r   c                     t               )z$Is the Leaf complex valued?
        r?   rA   s    r   r   zExpression.is_complex  rT   r   c                 ,    t        | j                        S )z7int : The number of entries in the expression.
        )r   rQ   rA   s    r   sizezExpression.size  s     tzz**r   c                 ,    t        | j                        S )zBint : The number of dimensions in the expression's shape.
        )lenrQ   rA   s    r   ndimzExpression.ndim  s     4::r   Norder)FCNc                     |2t         j                  dd      }t        j                  |t               d}|dv sJ  t        j                         | |      S )zi
        Vectorizes the expression.

        order: column-major ('F') or row-major ('C') order.
        	FUNC_NAMEflattenr   )r   r   )DEFAULT_ORDER_DEPRECATION_MSGreplacewarningswarnFutureWarningr   vec)r   r   flatten_order_warnings      r   r   zExpression.flatten  sT     =$A$I$I+W`$a!MM/?E
"""x||~dE**r   c                 :    t        d | j                  D              S )zIs the expression a scalar?c              3   &   K   | ]	  }|d k(    yw)r   NrV   )r{   ds     r   r}   z'Expression.is_scalar.<locals>.<genexpr>  s     .a16.s   )r~   rQ   rA   s    r   r   zExpression.is_scalar  s    .4::...r   c                 v    | j                   dk  xs) | j                   dk(  xr t        | j                        dk(  S )z)Is the expression a column or row vector?r      )r   minrQ   rA   s    r   	is_vectorzExpression.is_vector  s/    yyA~J$))q."IS_5IJr   c                 p    | j                   dk(  xr& | j                  d   dkD  xr | j                  d   dkD  S )zIs the expression a matrix?r   r   r   )r   rQ   rA   s    r   	is_matrixzExpression.is_matrix  s4    yyA~I$**Q-!"3I

18IIr   c                     t        |t              rt        |      dk(  r| S t        j                  |      r t        j                         | |      S  t        j                         | |      S )z2Return a slice/index into the expression.
        r   )r   tupler   kuis_special_slicer   special_indexindex)r   keys     r   __getitem__zExpression.__getitem__  sY    
 c5!c#h!mK  %+8))+D#66#8>>#D#..r   c                 X    | j                   dk  r| S  t        j                         |       S )z6Expression : The transpose of the expression.
        r   )r   r   	transposerA   s    r   TzExpression.T  s*    
 99>K'8%%'--r   c                     | j                         r| j                  S  t        j                         |       j                  S )z@Expression : The conjugate-transpose of the expression.
        )r   r   r   conjrA   s    r   HzExpression.H  s/     <<>66M"8==?4(***r   powerc                 8     t        j                         | |      S )zRaise expression to a power.

        Parameters
        ----------
        power : float
            The power to which to raise the expression.

        Returns
        -------
        Expression
            The expression raised to ``power``.
        )r   r   )r   r   s     r   __pow__zExpression.__pow__"  s      x~~e,,r   basec                     t        d      )NzCVXPY currently does not support variables on the right side of **. Consider using the identity that a**x = cp.exp(cp.multiply(np.log(a), x)).r?   )r   r   s     r   r+   zExpression.__rpow__1  s    ! #2 3 	3r   c                 ,    t         j                  |       S )z
        If expr_like is an Expression, return it. Otherwise, cast expr_like to a Constant.

        This is a wrapper around the misleadingly-named `Expression.cast_to_const` function.
        )r;   r   )	expr_likes    r   castzExpression.cast7  s     ''	22r   c                     t        | t              r"| D ]  }t        |t              st        d       t        | t              r| S  t	        j
                         |       S )z1Converts a non-Expression to a Constant.
        zzThe input must be a single CVXPY Expression, not a list. Combine Expressions using atoms such as bmat, hstack, and vstack.)r   listr;   
ValueErrorr   r   )rW   elems     r   r   zExpression.cast_to_constA  sa     dD! dJ/$\  "$
3tR9L9J9J9LT9RRr   c                    t         j                  |       } t         j                  |      }| j                         r1|j                         s!t        j                  | |j
                        } ne|j                         r1| j                         s!t        j                  || j
                        }n$| j                         r|j                         r| |fS | j                  dk(  r`|j                  dk(  rPt        d      D cg c](  }t        | j
                  |   |j
                  |         * }}| j
                  d   dk(  r2| j
                  d   |d   k  rt        j                  |d   df      | z  } |j
                  d   dk(  r2|j
                  d   |d   k  rt        j                  |d   df      |z  }| j
                  d   dk(  r2| j
                  d   |d   k  r| t        j                  d|d   f      z  } |j
                  d   dk(  r2|j
                  d   |d   k  r|t        j                  d|d   f      z  }| |fS | j                  dk\  s(|j                  dk\  s| j                  |j                  k7  rtt        j                  | j
                  |j
                        }| j
                  |k7  rt        j                  | |      } |j
                  |k7  rt        j                  ||      }| |fS c c}w )zBroadcast the binary operator.r   r   r      )r;   r   r   cppromoterQ   r   rangemaxr   onesbroadcast_shapesbroadcast_to)lh_exprrh_expridimsoutput_shapes        r   	broadcastzExpression.broadcastN  s{    **73**73w'8'8':jj'--8G ):):)<jj'--8G W%6%6%8G##<<1!2EJ1XNCa('--*:;NDN}}Q1$q)9DG)C''47A,/'9}}Q1$q)9DG)C''47A,/'9}}Q1$q)9DG)C!BGGQQL$99}}Q1$q)9DG)C!BGGQQL$99  \\Q',,!"3w||w||7S..w}}gmmLL}},//'<@}},//'<@% Os   >-K0r   c                     t        |t        j                               r|j                         r| S | j	                  | |      \  } } t        j
                         | |g      S z*Expression : Sum two expressions.
        )r   r   r   r   r  add_exprr   r   s     r   __add__zExpression.__add__q  sR     eX..01emmoKnnT51e"x  "D%=11r   c                 l    t        |t        j                               r|j                         r| S || z   S r
  )r   r   r   r   r  s     r   r   zExpression.__radd__z  s.     eX..01emmoKt|r   c                     | | z   S z8Expression : The difference of two expressions.
        rV   r  s     r   __sub__zExpression.__sub__  s     uf}r   c                     || z
  S r  rV   r  s     r   r"   zExpression.__rsub__       t|r   c                    | j                   dk(  s|j                   dk(  r t        j                         | |      S | j                   d   |j                   d   k7  r;| j                         s|j                         r t        j                         | |      S | j	                         s9|j	                         s)t        j                         rt        j                  d       t        j                         5  t        j                  dt        d       t        t        z  }t        j                  |t               t        j                  |t               t        dz  ad	d	d	        t        j                         | |      S # 1 sw Y   $xY w)
z5Expression : The product of two expressions.
        rV   r   zForming a nonconvex expression.alwaysT)appendr   N)rQ   r   
elmul_exprr   rY   r	   warnings_enabledr   r   catch_warningssimplefilterUserWarning__STAR_MATMUL_WARNING____STAR_MATMUL_COUNT__DeprecationWarningmatmul_expr)r   r   msgs      r   __mul__zExpression.__mul__  s.    ::u{{b0
 )8&&(u55ZZ^u{{1~-!U__%6 )8&&(u55
 $$&%*;*;*=))+MM"CD ((* +%%hDI-0EEc;/c#56%*%+ *8'')$66+ +s   1A'E;;Fc                    | j                   dk(  s|j                   dk(  rt        d      t        | t        j                               r_| j
                  d   |u rN|j                         s>| j
                  d   j                         r!ddlm}   |       || j
                  d         S  t        j                         | |      S )z?Expression : Matrix multiplication of two expressions.
        rV   0Scalar operands are not allowed, use '*' insteadr   r   )	quad_form)	rQ   r   r   r   r   r   rY   cvxpy.expressions.cvxtypesr%  )r   r   r%  s      r   
__matmul__zExpression.__matmul__  s     ::u{{b0OPPdH0023 yy|u$U->->-@TYYq\E]E]E_@"y{5$))A,77%x##%dE22r   c                 $    | j                  |      S )8Expression : One expression divided by another.
        )__div__r  s     r   __truediv__zExpression.__truediv__  s     ||E""r   c                     | j                  | |      \  } }| j                         s)|j                         s|j                  | j                  k(  r t        j                         | |      S t        d| j                  d|j                  d      )r)  z"Incompatible shapes for division (z / rN   )r  r   rQ   r   div_exprr   r  s     r   r*  zExpression.__div__  sq     nnT51eNN 1ekkTZZ6O&8$$&tU33!ZZ6 7 7r   c                     || z  S z5Expression : Called for Number / Expression.
        rV   r  s     r   r'   zExpression.__rdiv__  r  r   c                     || z  S r/  rV   r  s     r   __rtruediv__zExpression.__rtruediv__  r  r   c                     || z  S )z5Expression : Called for Number * Expression.
        rV   r  s     r   r%   zExpression.__rmul__  r  r   c                     | j                   dk(  s|j                   dk(  rt        d       t        j                         ||       S )z5Expression : Called for matrix @ Expression.
        rV   r$  )rQ   r   r   r   r  s     r   r)   zExpression.__rmatmul__  s?     ::u{{b0OPP%x##%eT22r   c                 6     t        j                         |       S )z5Expression : The negation of the expression.
        )r   neg_exprrA   s    r   __neg__zExpression.__neg__  s     #x  "4((r   c                     t        | |z
        S z:PSD : Creates a positive semidefinite inequality.
        r
   r  s     r   
__rshift__zExpression.__rshift__       4%<  r   c                     t        || z
        S r8  r9  r  s     r   r/   zExpression.__rrshift__       54<  r   c                     t        || z
        S z:PSD : Creates a negative semidefinite inequality.
        r9  r  s     r   
__lshift__zExpression.__lshift__  r=  r   c                     t        | |z
        S r?  r9  r  s     r   r-   zExpression.__rlshift__  r;  r   c                     t        |       S r   )idrA   s    r   __hash__zExpression.__hash__
  s    $xr   c                     t        | |      S )z;Equality : Creates a constraint ``self == other``.
        )r   r  s     r   r1   zExpression.__eq__  s     e$$r   c                     t        | |      S )zIInequality : Creates an inequality constraint ``self <= other``.
        r   r  s     r   r5   zExpression.__le__  s     $&&r   c                     t        d      Nz$Strict inequalities are not allowed.r?   r  s     r   r9   zExpression.__lt__      !"HIIr   c                     t        ||       S r   rG  r  s     r   r3   zExpression.__ge__  s    %&&r   c                     t        d      rI  r?   r  s     r   r7   zExpression.__gt__!  rJ  r   c                    	 t         |   }|i k(  r!t        |      dk(  r|d   | u r || |d         S |j                         dhk(  rUt        |      dk(  rG|d   | u r@t        |d   t              r-t        |d         dk(  r|d   |d   d   u rt        t              t        t              # t        $ r Y t        t              w xY w)Nr   r   r   out)	__BINARY_EXPRESSION_UFUNCS__r   keysr   r   RuntimeError__INPLACE_MUTATION_ERROR__KeyError__NUMPY_UFUNC_ERROR__)r   ufuncmethodr   kwargsufunc_handlers         r   __array_ufunc__zExpression.__array_ufunc__$  s    	8?M|INGtO$T47335')INGtOve}e4u&!+Gve}Q//"#=>>
 011  	011	s   .B) A)B) )	CCc                      t        t              r   )	TypeError__ABS_ERROR__rA   s    r   __abs__zExpression.__abs__8  s    &&r   c                     ddl m}  ||       S z0
        Equivalent to `cp.conj(self)`.
        r   )r   cvxpyr   r   r   s     r   r   zExpression.conj;       	Dzr   c                     ddl m}  ||       S r_  r`  rb  s     r   	conjugatezExpression.conjugateB  rc  r   r   c                      ddl m}  || |      S )z8
        Equivalent to `cp.cumsum(self, axis)`.
        r   )cumsum)ra  rg  )r   axisrg  s      r   rg  zExpression.cumsumI  s     	!dD!!r   )keepdimsc                "    ddl m}  || ||      S )z?
        Equivalent to `cp.max(self, axis, keepdims)`.
        r   )r   )ra  r   )r   rh  ri  max_s       r   r   zExpression.maxP       	&D$))r   c                "    ddl m}  || ||      S )z@
        Equivalent to `cp.mean(self, axis, keepdims)`.
        r   )mean)ra  rn  )r   rh  ri  rn  s       r   rn  zExpression.meanW       	D$))r   c                "    ddl m}  || ||      S )z?
        Equivalent to `cp.min(self, axis, keepdims)`.
        r   )r   )ra  r   )r   rh  ri  min_s       r   r   zExpression.min^  rl  r   c                "    ddl m}  || ||      S )z@
        Equivalent to `cp.prod(self, axis, keepdims)`.
        r   )prod)ra  rs  )r   rh  ri  rs  s       r   rs  zExpression.prode  ro  r   c                "    ddl m}  || ||      S )z?
        Equivalent to `cp.ptp(self, axis, keepdims)`.
        r   )ptp)ra  ru  )r   rh  ri  ru  s       r   ru  zExpression.ptpl  s     	4x((r   c                     |2t         j                  dd      }t        j                  |t               d}ddlm}  || ||      S )zA
        Equivalent to `cp.reshape(self, shape, order)`.
        r   reshaper   r   )rw  )r   r   r   r   r   ra  rw  )r   rQ   r   reshape_order_warningrw  s        r   rw  zExpression.reshapes  sC     =$A$I$I+W`$a!MM/?E!tUE**r   )ddofri  c                &    ddl m}  || |||      S )z?
        Equivalent to `cp.std(self, axis, keepdims)`.
        r   )std)rh  ry  ri  )ra  r{  )r   rh  ry  ri  r{  s        r   r{  zExpression.std~  s     	4dAAr   c                "    ddl m}  || ||      S )z?
        Equivalent to `cp.sum(self, axis, keepdims)`.
        r   )sum)ra  r}  )r   rh  ri  sum_s       r   r}  zExpression.sum  rl  r   c                     ddl m}  ||       S )z1
        Equivalent to `cp.trace(self)`.
        r   )trace)ra  r  )r   r  s     r   r  zExpression.trace  s     	 T{r   ry  c                "    ddl m}  || |      S )z/
        Equivalent to `cp.var(self)`.
        r   )varr  )ra  r  )r   ry  r  s      r   r  zExpression.var  s     	4d##r   )F)dcpr   )r=   r;   )rW   r;   )r  r;   r  r;   )r   )y__name__
__module____qualname____doc____array_priority__propertyabcabstractmethodr   r   ndarrayrB   rE   rG   rI   strrL   rR   rK   rW   r   rq   rO   rw   perfcompute_onceboolrY   r\   r^   r`   r   rb   rd   rf   rh   r   r   rl   rn   rj   r   r   r   r   r   r   r   r   r   r   rP   r   r   r   r   intrQ   r   r   r   r   r   r   r   r   r   r   r   r   r   floatr   r+   staticmethodr   r   r  r   ExpressionLiker  r   r  r"   r"  r'  r+  r*  r'   r1  r%   r)   r6  r
   r:  r/   r@  r-   rD  r   r1   r   r5   r9   r3   r7   rY  r]  r   re  rg  r   rn  r   rs  ru  rw  r{  r}  r  r  rV   r   r   r;   r;   t   s    $x

+ $  $
Xbjj1 
 $  $ $  $ 
7# 7 	$c $ $
  
 DI  ( 3  6 3   
4T 4 4 
N4 N N
 	$4 $ $
 	$D $ $
 
5$ 54 5 5&	ET 	E 
M4 M M 	$4 $ $
 	$D $ $
E$ E4 E 	$c $d $ $
   ! !@ @ 
? ? ?8d 8
  "d ""D " d  4 
" "4 4 c   
5 5 5
 	$4 $ $
 	$4 $ $
 $uS#X $  $
% %
 $ $  $
 	$D $ $
 +c + +
 c  
+W^4 +/4 /K4 KJ4 J
/ . . + +-U -| -3U 3| 3 3 3 
S 
S      D 2^ 2 2 2 n    ^   
 n   
 7^ 7 7 7B 3 3< 3 3  # #L # #
 7^ 7 7 7 n   
 . \  
 n   
 3 3L 3 3)
 ! !3 ! !
 ! !C ! !
 ! !3 ! !
 ! !C ! !#  %N %x % %
 'N 'z ' '
JN J 'N 'z ' 'JN J2('"* **% ** **% *) )	+GN$; 	+| 	+BQ B* *  $r   r;   )<r  r  r   	functoolsr   typingr   r   r   r   numpyr   ra  r   cvxpy.settingssettingsrZ   cvxpy.utilities	utilitiesucvxpy.utilities.key_utils	key_utilsr   !cvxpy.utilities.performance_utilsperformance_utilsr  r	   cvxpy.constraintsr
   r   r   cvxpy.expressionsr   r   cvxpy.utilities.shaper   r   r  r  rT  rR  r\  r   addsubtractmultiplydividematmulr   
left_shiftright_shiftequal
less_equalgreater_equallessgreaterrO  r  	Canonicalr;   rV   r   r   <module>r     s$       1 1     & & 0 0  7 7 & " 1&       	0
5
5
		3
		6
2
:
;
0 	5
8
/


2  & 4d$ d$r   