
    `i
                     T    d dl Z d dlZd dlZd dlmZ ddZd Zd ZddZdd	Z	d
 Z
dS )    N)internalc                 V    t          j        || j                  }t          | |          S )a  Reverse the order of elements in an array along the given axis.

    Note that ``flip`` function has been introduced since NumPy v1.12.
    The contents of this document is the same as the original one.

    Args:
        a (~cupy.ndarray): Input array.
        axis (int or tuple of int or None): Axis or axes along which to flip
            over. The default, ``axis=None``, will flip over all of the axes of
            the input array. If axis is negative it counts from the last to the
            first axis. If axis is a tuple of ints, flipping is performed on
            all of the axes specified in the tuple.

    Returns:
        ~cupy.ndarray: Output array.

    .. seealso:: :func:`numpy.flip`

    )r   _normalize_axis_indicesndim_flip)aaxisaxess      p/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupy/_manipulation/rearrange.pyflipr   	   s&    ( +D!&99DD>>    c                 T    | j         dk     rt          d          | dddddf         S )aA  Flip array in the left/right direction.

    Flip the entries in each row in the left/right direction. Columns
    are preserved, but appear in a different order than before.

    Args:
        a (~cupy.ndarray): Input array.

    Returns:
        ~cupy.ndarray: Output array.

    .. seealso:: :func:`numpy.fliplr`

       Input must be >= 2-dNr   
ValueErrorr   s    r   fliplrr   !   s6     	vzz/000RRR2X;r   c                 L    | j         dk     rt          d          | ddd         S )a;  Flip array in the up/down direction.

    Flip the entries in each column in the up/down direction. Rows are
    preserved, but appear in a different order than before.

    Args:
        a (~cupy.ndarray): Input array.

    Returns:
        ~cupy.ndarray: Output array.

    .. seealso:: :func:`numpy.flipud`

       zInput must be >= 1-dNr   r   r   s    r   flipudr   5   s-     	vzz/000TTrT7Nr   c                 n    |;t                                           |d                               j                  S t	          j        |          r|fn|}t           fd|D                       }t          |t          j	                  rk|                                }t          t          |          |j                  }t	          j        ||f          }t          j        ||f          }g }t           j                  D ]b}dg j        z  } j        |         ||<   |                    t          j         j        |                                       |                     ct%          ||          D ]0\  }}||xx         |z  cc<   ||xx          j        |         z  cc<   1t           j                  D ]%}t          j        ||          j                  ||<   & t          |                   S t	          j        ||          }	|	j        dk    rt+          d          d t           j                  D             }
|	D ]\  }}|
|xx         |z  cc<   t-          d          t-          d          ffg j        z  }|
                                D ]^\  }}| j        |         pdz  }|rEt-          d|           t-          |d          ft-          | d          t-          d|          ff||<   _t          j                   }t3          j        | D ]}t%          | \  }} |         ||<   |S )a@  Roll array elements along a given axis.

    Elements that roll beyond the last position are re-introduced at the first.

    Args:
        a (~cupy.ndarray): Array to be rolled.
        shift (int or tuple of int): The number of places by which elements are
            shifted. If a tuple, then `axis` must be a tuple of the same size,
            and each of the given axes is shifted by the corresponding number.
            If an int while `axis` is a tuple of ints, then the same value is
            used for all given axes.
        axis (int or tuple of int or None): The axis along which elements are
            shifted. By default, the array is flattened before shifting, after
            which the original shape is restored.

    Returns:
        ~cupy.ndarray: Output array.

    .. seealso:: :func:`numpy.roll`

    Nr   c                 D    g | ]}t          j        |j                  S  )r   _normalize_axis_indexr   ).0axr   s     r   
<listcomp>zroll.<locals>.<listcomp>c   s5       79&r1622  r   r   z4'shift' and 'axis' should be scalars or 1D sequencesc                     i | ]}|d S )r   r   )r   r   s     r   
<dictcomp>zroll.<locals>.<dictcomp>   s    000B"a000r   )rollravelreshapeshapenumpyisscalartuple
isinstancecupyndarraymaxlensizebroadcast_toranger   appendarangezip	broadcastndr   sliceitems
empty_like	itertoolsproduct)r   shiftr	   r
   n_axesindicesr   	ind_shapesbroadcastedshiftsshrollsoffsetresult	arr_index	res_indexs   `                r   r"   r"   I   s\   , |AGGIIua((00999nT**4D77D    =A    D %&& +SYY
++!$	22!%&33 -- 	H 	HBafIGBKIbMNN4;qwr{33;;IFFGGGGu%% 	' 	'EBBKKK1KKKBKKK172;&KKKK-- 	B 	BB+GBKAAGBKKw  oeT22>AJL L L00%--000! 	 	FB2JJJ"JJJJ;;d,./!&8 ,,.. 	J 	JJBagbk&Q&F J#D6'22E&$4G4GH#VGT22E$4G4GHJb	 ## (%0 	- 	-G#&= Iy !)F9r   r   r   r   c                 H   | j         }|dk     rt          d          t          |          }t          |          dk    rt          d          |d         |d         k    s"t	          |d         |d         z
            |k    rt          d          | |d         cxk    r|k     rn n| |d         cxk    r|k     sn t          d| |fz            |dz  }|dk    r
| d	d	         S |dk    rt          | |          S t          t          d|                    }||d                  ||d                  c||d         <   ||d         <   |dk    r*t          j	        t          | |d         f          |          S t          t          j	        | |          |d         f          S )
a-  Rotate an array by 90 degrees in the plane specified by axes.

    Note that ``axes`` argument has been introduced since NumPy v1.12.
    The contents of this document is the same as the original one.

    Args:
        a (~cupy.ndarray): Array of two or more dimensions.
        k (int): Number of times the array is rotated by 90 degrees.
        axes: (tuple of ints): The array is rotated in the plane defined by
            the axes. Axes must be different.

    Returns:
        ~cupy.ndarray: Output array.

    .. seealso:: :func:`numpy.rot90`

    r   r   zlen(axes) must be 2r   r   zaxes must be differentzaxes must be >= %d and < %d   N)
r   r   r(   r-   absr   listr0   r*   	transpose)r   kr
   a_ndimaxes_ts        r   rot90rQ      s   $ VFzz/000;;D
4yyA~~.///Aw$q'Sa47!233v==1222GtAw'''''''''VGtAw,G,G,G,G,G,G,G,G66'69JJKKK	AAAvvtAvvQ~~%6""##F'-d1gtAw$F47OVDG_Avv~eAQz22F;;;T^Av..a
;;;r   c                     t          d           g| j        z  }|D ]}t          d d d          ||<   | t          |                   S )Nr   )r6   r   r(   )r   r
   indexerr   s       r   r   r      sM    T{{maf$G , ,D$++U7^^r   )N)r   rH   )r9   r&   r*   
cupy._corer   r   r   r   r"   rQ   r   r   r   r   <module>rU      s                  0  (  (H H H HV+< +< +< +<\    r   