o
    Ö°“iˆ  ã                   @   sœ   d dl Z d dl mZ d dlm  mZ dd„ dd„ dd„ dd„ dd„ d	d„ d
œZdd„ Zdd„ Zdd„ Zdd„ Z	ej
Z
dd„ Zdd„ Zdd„ Zddd„ZdS )é    N)Ú_corec                 C   ó   dS ©N)é   © ©Úshaper   r   úK/home/ubuntu/.local/lib/python3.10/site-packages/cupy/_manipulation/dims.pyÚ<lambda>	   ó    r
   c                 C   r   )N)r   r   r   r   r   r   r	   r
   
   r   c                 C   s   d|  S r   r   r   r   r   r	   r
      ó    c                 C   r   )N)r   r   r   r   r   r   r   r	   r
      r   c                 C   s   d|  d S r   r   r   r   r   r	   r
      s    c                 C   s   | d S r   r   r   r   r   r	   r
      r   ))r   r   )é   r   )r   r   )é   r   )r   r   )r   r   c                 C   s`   g }|D ] }t  |¡}|j| k rt| |jf |jƒ}|j|Ž }| |¡ qt|ƒdkr.|\}|S )z)Helper function for atleast_nd functions.r   )ÚcupyÚasarrayÚndimÚ_atleast_nd_shape_mapr   ÚreshapeÚappendÚlen)ÚnÚarysÚresÚaÚ	new_shaper   r   r	   Ú_atleast_nd_helper   s   


r   c                  G   ó
   t d| ƒS )a­  Converts arrays to arrays with dimensions >= 1.

    Args:
        arys (tuple of arrays): Arrays to be converted. All arguments must be
            :class:`cupy.ndarray` objects. Only zero-dimensional array is
            affected.

    Returns:
        If there are only one input, then it returns its converted version.
        Otherwise, it returns a list of converted arrays.

    .. seealso:: :func:`numpy.atleast_1d`

    r   ©r   ©r   r   r   r	   Ú
atleast_1d"   s   
r   c                  G   r   )a  Converts arrays to arrays with dimensions >= 2.

    If an input array has dimensions less than two, then this function inserts
    new axes at the head of dimensions to make it have two dimensions.

    Args:
        arys (tuple of arrays): Arrays to be converted. All arguments must be
            :class:`cupy.ndarray` objects.

    Returns:
        If there are only one input, then it returns its converted version.
        Otherwise, it returns a list of converted arrays.

    .. seealso:: :func:`numpy.atleast_2d`

    r   r   r   r   r   r	   Ú
atleast_2d4   s   
r    c                  G   r   )a?  Converts arrays to arrays with dimensions >= 3.

    If an input array has dimensions less than three, then this function
    inserts new axes to make it have three dimensions. The place of the new
    axes are following:

    - If its shape is ``()``, then the shape of output is ``(1, 1, 1)``.
    - If its shape is ``(N,)``, then the shape of output is ``(1, N, 1)``.
    - If its shape is ``(M, N)``, then the shape of output is ``(M, N, 1)``.
    - Otherwise, the output is the input array itself.

    Args:
        arys (tuple of arrays): Arrays to be converted. All arguments must be
            :class:`cupy.ndarray` objects.

    Returns:
        If there are only one input, then it returns its converted version.
        Otherwise, it returns a list of converted arrays.

    .. seealso:: :func:`numpy.atleast_3d`

    r   r   r   r   r   r	   Ú
atleast_3dH   s   
r!   c                  G   s   t t| Ž jƒS )zØBroadcasts given arrays.

    Args:
        args (tuple of arrays): Arrays to broadcast for each other.

    Returns:
        list: A list of broadcasted arrays.

    .. seealso:: :func:`numpy.broadcast_arrays`

    )ÚlistÚ	broadcastÚvalues)Úargsr   r   r	   Úbroadcast_arrayse   s   r&   c                 C   s   t  | |¡S )a  Broadcast an array to a given shape.

    Args:
        array (cupy.ndarray): Array to broadcast.
        shape (tuple of int): The shape of the desired array.

    Returns:
        cupy.ndarray: Broadcasted view.

    .. seealso:: :func:`numpy.broadcast_to`

    )r   Úbroadcast_to)Úarrayr   r   r   r	   r'   t   s   r'   c                 C   s"   t |ƒttfvr|f}t | |¡S )a3  Expands given arrays.

    Args:
        a (cupy.ndarray): Array to be expanded.
        axis (int): Position where new axis is to be inserted.

    Returns:
        cupy.ndarray: The number of dimensions is one greater than that of
        the input array.

    .. seealso:: :func:`numpy.expand_dims`

    )ÚtypeÚtupler"   Ú_manipulationÚ_expand_dims©r   Úaxisr   r   r	   Úexpand_dims„   s   r/   c                 C   s
   |   |¡S )a¸  Removes size-one axes from the shape of an array.

    Args:
        a (cupy.ndarray): Array to be reshaped.
        axis (int or tuple of ints): Axes to be removed. This function removes
            all size-one axes by default. If one of the specified axes is not
            of size one, an exception is raised.

    Returns:
        cupy.ndarray: An array without (specified) size-one axes.

    .. seealso:: :func:`numpy.squeeze`

    )Úsqueezer-   r   r   r	   r0   —   s   
r0   )N)r   r   Ú!cupy._core._routines_manipulationÚ_routines_manipulationr+   r   r   r   r    r!   r#   r&   r'   r/   r0   r   r   r   r	   Ú<module>   s&    ú
