
    
9j3                    d    S SK Jr  S SKrS SKrS SKrS SKJr  S
S jrS rS r	S
S jr
SS jrS	 rg)    )annotationsN)internalc                X    [         R                  " XR                  5      n[        X5      $ )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      V/home/wildlama/miniconda3/lib/python3.13/site-packages/cupy/_manipulation/rearrange.pyflipr      s"    ( ++D&&9D>    c                P    U R                   S:  a  [        S5      eU SS2SSS24   $ )a!  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   #   s-     	vvz/00R2X;r   c                H    U R                   S:  a  [        S5      eU SSS2   $ )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   7   s(     	vvz/00TrT7Nr   c           	        Uc4  [        U R                  5       US5      R                  U R                  5      $ [        R
                  " U5      (       a  U4OUn[        U Vs/ s H#  n[        R                  " X@R                  5      PM%     sn5      n[        U[        R                  5      (       Gae  UR                  5       n[        [        U5      UR                  5      n[        R                   " X545      n[        R                   " X45      n/ n[#        U R                  5       He  nS/U R                  -  nU R                  U   Xt'   UR%                  [        R&                  " U R                  U   5      R                  U5      5        Mg     [)        X15       H*  u  pHXd==   U-  ss'   Xd==   U R                  U   -  ss'   M,     [#        U R                  5       H(  n[        R                   " Xd   U R                  5      Xd'   M*     U [        U5         $ [        R*                  " X5      n	U	R,                  S:  a  [/        S5      e[#        U R                  5       Vs0 s H  oDS_M     n
nU	 H  u  pX==   [1        U5      -  ss'   M     [3        S5      [3        S5      44/U R                  -  nU
R5                  5        H\  u  pMXR                  U   =(       d    S-  nU(       d  M(  [3        SU* 5      [3        US5      4[3        U* S5      [3        SU5      44X'   M^     [        R6                  " U 5      n[8        R:                  " U6  H  n[)        U6 u  nnX   UU'   M     U$ s  snf s  snf )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   r   z4'shift' and 'axis' should be scalars or 1D sequences)rollravelreshapeshapenumpyisscalartupler   _normalize_axis_indexr   
isinstancecupyndarraymaxlensizebroadcast_torangeappendarangezip	broadcastndr   intsliceitems
empty_like	itertoolsproduct)r	   shiftr
   r   axn_axesindices	ind_shapesbroadcastedshiftsshrollsoffsetresult	arr_index	res_indexs                    r   r   r   K   s   , |AGGIua(0099nnT**D7D=A=Ar&&r662T D %&&SY

+!!$	2!!%3 -BaffIGGBKIMNN4;;qwwr{3;;IFG  
 %EBK1KK1772;&K & -B++GKAGK   w  ooe2>>AJL L"'-0-Ba%-0!FBJ#b'!J " ;d,./!&&8 ,,.JBggbk&Q&Fv#D6'2E&$4GH#VGT2E$4GHJ		 ) # ((%0G#&= Iy !F9 1 ]: 1s   !*M&M+c                   U R                   nUS:  a  [        S5      e[        U5      n[        U5      S:w  a  [        S5      eUS   US   :X  d  [	        US   US   -
  5      U:X  a  [        S5      eU* US   s=::  a  U:  a  O  OU* US   s=::  a  U:  d  O  [        SU* U4-  5      eUS-  nUS:X  a  U S	S	 $ US:X  a  [        X5      $ [        [        SU5      5      nXBS      XBS      sXBS   '   XBS   '   US:X  a$  [        R                  " [        XS   45      U5      $ [        [        R                  " X5      US   45      $ )
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   listr*   r$   	transpose)r	   kr   a_ndimaxes_ts        r   rot90rL      sP   $ VVFz/00;D
4yA~.//Aw$q'Sa47!23v=122GtAw''VGtAw,G,G66'69JJKK	AAAvtAvQ~%6"#F'-1gAw$F7OVG_Av~~eAQz2F;;T^^A.a
;;r   c                    [        S 5      /U R                  -  nU H  n[        S S S5      X#'   M     U [        U5         $ )Nr   )r1   r   r!   )r	   r   indexerr7   s       r   r   r      sA    T{maff$GD$+  U7^r   )N)r   )r   r   )
__future__r   r4   r   r$   
cupy._corer   r   r   r   r   rL   r    r   r   <module>rR      s5    "    0((HV+<\r   