
    bi#                         d Z ddlmZmZ ddl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 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.
    )ListTupleN)AffAtom)
Constraint)is_param_freec                        e Zd ZdZd fdZej                  d        ZddZde	e
e
f   fdZdefdZdefdZde	eef   fd	Zdefd
ZdefdZd Zd Z	 dde	e
df   de	ej*                  ee   f   fdZ xZS )kronzKronecker product.
    returnc                 .    t         t        |   ||       y N)superr	   __init__)selflh_exprrh_expr	__class__s      R/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/atoms/affine/kron.pyr   zkron.__init__!   s    dD"7G4    c                 :    t        j                  |d   |d         S )z-Kronecker product of the two values.
        r      )npr	   )r   valuess     r   numericzkron.numeric$   s     wwvay&),,r   c                    | j                   d   j                         s(| j                   d   j                         st        d      | j                   d   j                  dk7  s| j                   d   j                  dk7  rt        d      y)zKChecks that both arguments are vectors, and the first is constant.
        r   r   z/At least one argument to kron must be constant.   z'kron requires both arguments to be 2-d.N)argsis_constant
ValueErrorndimr   s    r   validate_argumentszkron.validate_arguments*   ss     		!((*diil.F.F.HNOOYYq\!#tyy|'8'8A'=FGG (>r   c                     | j                   d   j                  d   | j                   d   j                  d   z  }| j                   d   j                  d   | j                   d   j                  d   z  }||fS )Nr   r   )r   shape)r   rowscolss      r   shape_from_argszkron.shape_from_args2   sl    yy|!!!$TYYq\%7%7%::yy|!!!$TYYq\%7%7%::Tzr   c                 j   t         j                  j                         rZ| j                  d   }| j                  d   }|j	                         xs |j	                         xr t        |      xr t        |      S | j                  d   j	                         xs | j                  d   j	                         S )zIs the atom convex?
        r   r   )uscopesdpp_scope_activer   r   r   )r   xys      r   is_atom_convexzkron.is_atom_convex7   s     88$$&		!A		!A]]_7 <"1%:-*:= 99Q<++-K11I1I1KKr   c                 "    | j                         S )zIs the atom concave?
        )r-   r    s    r   is_atom_concavezkron.is_atom_concaveC   s     ""$$r   c                 v    t         j                  j                  | j                  d   | j                  d         S )zSame as times.
        r   r   )r(   signmul_signr   r    s    r   sign_from_argszkron.sign_from_argsH   s)     vvtyy|TYYq\::r   c                 ~    | j                   d   j                         rdnd}| j                   |   j                         S )z;Is the composition non-decreasing in argument idx?
        r   r   )r   r   	is_nonnegr   idxcst_locs      r   is_incrzkron.is_incrM   6     yy|//1!qyy!++--r   c                 ~    | j                   d   j                         rdnd}| j                   |   j                         S )z;Is the composition non-increasing in argument idx?
        r   r   )r   r   	is_nonposr6   s      r   is_decrzkron.is_decrS   r:   r   c                     | j                   d   j                         xr | j                   d   j                         }| j                   d   j                         xr | j                   d   j                         }|xs |S )zCheck a *sufficient condition* that the expression is PSD,
        by checking if both arguments are PSD or both are NSD.
        r   r   r   is_psdis_nsdr   case1case2s      r   r@   zkron.is_psdY   f     		!##%?$))A,*=*=*?		!##%?$))A,*=*=*?~r   c                     | j                   d   j                         xr | j                   d   j                         }| j                   d   j                         xr | j                   d   j                         }|xs |S )zCheck a *sufficient condition* that the expression is NSD,
        by checking if one argument is PSD and the other is NSD.
        r   r   r?   rB   s      r   rA   zkron.is_nsda   rE   r   r#   .c                     | j                   d   j                         rt        j                  |d   |d   |      g fS t        j                  |d   |d   |      g fS )a  Kronecker product of two matrices.

        Parameters
        ----------
        arg_objs : list
            LinOp for each argument.
        shape : tuple
            The shape of the resulting expression.
        data :
            Additional data required by the atom.

        Returns
        -------
        tuple
            (LinOp for objective, list of constraints)
        r   r   )r   r   lukron_rkron_l)r   arg_objsr#   datas       r   graph_implementationzkron.graph_implementationi   sX    & 99Q<##%99Xa[(1+u=rAA99Xa[(1+u=rAAr   )r
   Nr   )__name__
__module____qualname____doc__r   r   numpy_numericr   r!   r   intr&   boolr-   r/   r3   r9   r=   r@   rA   loLinOpr   r   rM   __classcell__)r   s   @r   r	   r	      s    5 - -
HsCx 

L 
L% %
;dDj 1 ;
.d ..d . 6:B$S#XB	rxxj))	*Br   r	   )rQ   typingr   r   numpyr   cvxpy.lin_ops.lin_oplin_opslin_oprU   cvxpy.lin_ops.lin_utils	lin_utilsrH   cvxpy.utilities	utilitiesr(   cvxpy.atoms.affine.affine_atomr   cvxpy.constraints.constraintr   %cvxpy.expressions.constants.parameterr   r	    r   r   <module>re      s:      ! ! $ $  2 3 ?cB7 cBr   