
    bi9                         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  G d de      Zdee   fd	Zd
edefdZdee   dee   fd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)
Constraintc                        e Zd ZdZdd fdZdefdZej                  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edf   fdZd Z	 ddeedf   deej*                  ee   f   fdZ xZS )	transposez}Transpose an expression.
    
    For an n-D expression, if axes are given, the order indicates the permutation of axes.
    returnc                 :    || _         t        t        |   |       y N)axessuperr   __init__)selfexprr   	__class__s      W/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/atoms/affine/transpose.pyr   ztranspose.__init__    s    	gt%d+    c                 ~    | j                   | j                  d    dS d| j                  d    d| j                    dS )Nr   z.Tz
transpose(z, axes=))r   argsr   s    r   nameztranspose.name%   sB    99iil^2&&		!~WTYYKqAAr   c                 J    t        j                  |d   | j                        S )Nr   r   )npr   r   )r   valuess     r   numericztranspose.numeric,   s    ||F1IDII66r   c                      y)z$Is the atom log-log convex?
        T r   s    r   is_atom_log_log_convexz transpose.is_atom_log_log_convex0        r   c                      y)z%Is the atom log-log concave?
        Tr   r   s    r   is_atom_log_log_concavez!transpose.is_atom_log_log_concave5   r!   r   c                 <    | j                   d   j                         S )z%Is the expression symmetric?
        r   )r   is_symmetricr   s    r   r%   ztranspose.is_symmetric:        yy|((**r   c                 <    | j                   d   j                         S )z*Is the expression skew-symmetric?
        r   )r   is_skew_symmetricr   s    r   r(   ztranspose.is_skew_symmetric?   s     yy|--//r   c                 <    | j                   d   j                         S )z%Is the expression Hermitian?
        r   )r   is_hermitianr   s    r   r*   ztranspose.is_hermitianD   r&   r   .c                     t        j                  | j                  d   j                  t        j                  g             }t        j
                  || j                        j                  S )z7Returns the shape of the transpose expression.
        r   )dtyper   )r   emptyr   shaper,   r   r   )r   arrs     r   shape_from_argsztranspose.shape_from_argsI   sE     hhtyy|))">||Cdii0666r   c                     | j                   gS )z,Returns the axes for transposition.
        r   r   s    r   get_dataztranspose.get_dataO   s     		{r   r.   c                 L    t        j                  |d   | j                        g fS )a  Create a new variable equal to the argument transposed.

        Parameters
        ----------
        arg_objs : list
            LinExpr 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   )lur   r   )r   arg_objsr.   datas       r   graph_implementationztranspose.graph_implementationT   s"    & Xa[$))4b99r   r   )r	   N)__name__
__module____qualname____doc__r   strr   r   numpy_numericr   boolr    r#   r%   r(   r*   r   intr0   r2   loLinOpr   r   r7   __classcell__)r   s   @r   r   r      s    
,
Bc B 7 7 
 
+d +
04 0
+d +
7sCx 7 6::$S#X:	rxxj))	*:r   r   r   c                     t        | |      S )aY  Permute the dimensions of the expression.

    Alias for transpose with specified axes.

    Parameters
    ----------
    expr : AffAtom
        The expression to permute dimensions of.
    axes : list or tuple of int
        The new order of the axes.

    Returns
    -------
    AffAtom
        A transpose atom with the specified axes.
    r   )r   )r   r   s     r   permute_dimsrD   i   s    " T%%r   axis1axis2c                     t        t        t        | j                                    }||   ||   c||<   ||<   t	        | |      S )a5  Swap two axes of the expression.

    Parameters
    ----------
    expr : AffAtom
        The expression to swap axes of.
    axis1 : int
        The first axis to swap.
    axis2 : int
        The second axis to swap.

    Returns
    -------
    AffAtom
        A transpose atom with the axes swapped.
    r   )listrangelenr.   r   )r   rE   rF   r   s       r   swapaxesrK   |   sD    " c$**o&'D#E{DKDKeT%%r   sourcedestinationc                 l   t        |t              rt        |t              st        d      t        |      t        |      k7  rt	        d      t        | j                        D cg c]	  }||vs| }}t        t        ||            D ]  \  }}|j                  ||        t        | |      S c c}w )a|  Move axes of the expression to new positions.

    Parameters
    ----------
    expr : AffAtom
        The expression to move axes of.
    source : list of int
        The original positions of the axes to move.
    destination : list of int
        The new positions for the moved axes.

    Returns
    -------
    AffAtom
        A new transpose atom with the axes moved.
    z1Source and destination must be lists of integers.z1Source and destination must have the same length.r   )
isinstancerH   	TypeErrorrJ   
ValueErrorrI   ndimsortedzipinsertr   )r   rL   rM   norderdestsrcs          r   moveaxisrZ      s    " fd#:k4+HKLL
6{c+&&LMMdii(<1AVOQ<E<CV45  	cT3  T&& =s   %	B1/B1)r;   typingr   r   numpyr   cvxpy.lin_ops.lin_oplin_opslin_opr@   cvxpy.lin_ops.lin_utils	lin_utilsr4   cvxpy.atoms.affine.affine_atomr   cvxpy.constraints.constraintr   r   r?   rD   rK   rZ   r   r   r   <module>rd      sq      ! ! $ $ 2 3M: M:^&T#Y &&&# &c &*'49 '49 'r   