o
    Ô0 i
  ã                   @   s^   d dl Z d dlZd dlZd dlmZ ddd„Zdd„ Zdd„ Zdd	d
„Zddd„Z	dd„ Z
dS )é    N)Úinternalc                 C   s   t  || 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   Z_normalize_axis_indicesÚndimÚ_flip)ÚaÚaxisÚaxes© r   úh/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/cupy/_manipulation/rearrange.pyÚflip	   s   
r
   c                 C   s(   | 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   r   r   r	   Úfliplr!   s   
r   c                 C   s    | 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   r   r   r	   Úflipud5   s   
r   c                    s<  |du rt ˆ  ¡ |dƒ ˆ j¡S t |¡r|fn|}t‡ fdd„|D ƒƒ}t|tj	ƒr | ¡ }t
t|ƒ|jƒ}t ||f¡}t ||f¡}g }tˆ jƒD ]}dgˆ j }ˆ j| ||< | t ˆ j| ¡ |¡¡ qLt||ƒD ]\}}||  |8  < ||  ˆ j| ;  < qotˆ jƒD ]}t || ˆ j¡||< qŒˆ t|ƒ S t ||¡}	|	jdkr¯tdƒ‚dd„ tˆ jƒD ƒ}
|	D ]\}}|
|  |7  < q»tdƒtdƒffgˆ j }|
 ¡ D ](\}}|ˆ j| päd; }|rtd| ƒt|dƒft| dƒtd|ƒff||< qÙt ˆ ¡}tj|Ž D ]}t|Ž \}}ˆ | ||< q|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                    s   g | ]	}t  |ˆ j¡‘qS r   )r   Z_normalize_axis_indexr   ©Ú.0Úaxr   r   r	   Ú
<listcomp>c   s    ÿzroll.<locals>.<listcomp>r   z4'shift' and 'axis' should be scalars or 1D sequencesc                 S   s   i | ]}|d “qS )r   r   r   r   r   r	   Ú
<dictcomp>€   s    zroll.<locals>.<dictcomp>)ÚrollZravelZreshapeÚshapeÚnumpyZisscalarÚtupleÚ
isinstanceÚcupyZndarrayÚmaxÚlenÚsizeZbroadcast_toÚranger   ÚappendZarangeÚzipÚ	broadcastÚndr   ÚsliceÚitemsZ
empty_likeÚ	itertoolsÚproduct)r   Úshiftr   r   Zn_axesÚindicesr   Z	ind_shapeÚsZbroadcastedZshiftsÚshZrollsÚoffsetÚresultZ	arr_indexZ	res_indexr   r   r	   r   I   sV   ÿ
ÿÿ€
r   r   ©r   r   c                 C   sL  | j }|dk rtdƒ‚t|ƒ}t|ƒdkrtdƒ‚|d |d ks-t|d |d  ƒ|kr1tdƒ‚| |d   kr>|k rNn n| |d   krM|k sWn td| |f ƒ‚|d }|dkre| d	d	… S |dkrnt| |ƒS ttd|ƒƒ}||d  ||d  ||d < ||d < |dkršt 	t| |d fƒ|¡S tt 	| |¡|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   Úlistr"   r   Z	transpose)r   Úkr   Za_ndimZaxes_tr   r   r	   Úrot90”   s(   (:
*r6   c                 C   s6   t d ƒg| j }|D ]
}t d d dƒ||< q
| t|ƒ S )Nr   )r'   r   r   )r   r   Zindexerr   r   r   r	   r   Â   s   r   )N)r   r1   )r)   r   r   Z
cupy._corer   r
   r   r   r   r6   r   r   r   r   r	   Ú<module>   s    


K.