o
    in                     @   sl   d dl Z d dl mZ dd ZddddddZd	d
 ZdddddZdddddZddddddZdS )    N)_corec                 C   sx   t dd | D rtdt| }t|D ] \}}|jdkr,|ddtjf }|||< q|jdkr5tdqt|ddS )	a{  Stacks 1-D and 2-D arrays as columns into a 2-D array.

    A 1-D array is first converted to a 2-D column array. Then, the 2-D arrays
    are concatenated along the second axis.

    Args:
        tup (sequence of arrays): 1-D or 2-D arrays to be stacked.

    Returns:
        cupy.ndarray: A new 2-D array of stacked columns.

    .. seealso:: :func:`numpy.column_stack`

    c                 s   s    | ]
}t |tj V  qd S )N)
isinstancecupyndarray.0a r	   T/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/cupy/_manipulation/join.py	<genexpr>   s    zcolumn_stack.<locals>.<genexpr>z&Only cupy arrays can be column stacked   N   z4Only 1 or 2 dimensional arrays can be column stackedaxis)	any	TypeErrorlist	enumeratendimr   newaxis
ValueErrorconcatenate)tuplstir   r	   r	   r
   column_stack   s   


r   	same_kinddtypecastingc                C   s,   |du rdd | D } d}t | ||||S )u$  Joins arrays along an axis.

    Args:
        tup (sequence of arrays): Arrays to be joined. All of these should have
            same dimensionalities except the specified axis.
        axis (int or None): The axis to join arrays along.
            If axis is None, arrays are flattened before use.
            Default is 0.
        out (cupy.ndarray): Output array.
        dtype (str or dtype): If provided, the destination array will have this
            dtype. Cannot be provided together with ``out``.
        casting ({‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optional):
            Controls what kind of data casting may occur. Defaults to
            ``'same_kind'``.

    Returns:
        cupy.ndarray: Joined array.

    .. seealso:: :func:`numpy.concatenate`

    Nc                 S   s   g | ]}|  qS r	   )ravelr   mr	   r	   r
   
<listcomp>:   s    zconcatenate.<locals>.<listcomp>r   )r   concatenate_methodr   r   outr   r   r	   r	   r
   r   #   s   r   c                 C   s   t dd | D dS )a  Stacks arrays along the third axis.

    Args:
        tup (sequence of arrays): Arrays to be stacked. Each array is converted
            by :func:`cupy.atleast_3d` before stacking.

    Returns:
        cupy.ndarray: Stacked array.

    .. seealso:: :func:`numpy.dstack`

    c                 S      g | ]}t |qS r	   )r   
atleast_3dr!   r	   r	   r
   r#   L       zdstack.<locals>.<listcomp>r   r   )r   r	   r	   r
   dstack?   s   r+   c                C   s4   dd | D }d}|d j dkrd}t||||dS )u  Stacks arrays horizontally.

    If an input array has one dimension, then the array is treated as a
    horizontal vector and stacked along the first axis. Otherwise, the array is
    stacked along the second axis.

    Args:
        tup (sequence of arrays): Arrays to be stacked.
        dtype (str or dtype): If provided, the destination array will have this
            dtype.
        casting ({‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optional):
            Controls what kind of data casting may occur. Defaults to
            ``'same_kind'``.

    Returns:
        cupy.ndarray: Stacked array.

    .. seealso:: :func:`numpy.hstack`

    c                 S   r'   r	   )r   
atleast_1dr   r	   r	   r
   r#   d   r)   zhstack.<locals>.<listcomp>r   r   r   )r   r   )r   r   r   arrsr   r	   r	   r
   hstackO   s
   r.   c                C   s   t dd | D d||dS )u  Stacks arrays vertically.

    If an input array has one dimension, then the array is treated as a
    horizontal vector and stacked along the additional axis at the head.
    Otherwise, the array is stacked along the first axis.

    Args:
        tup (sequence of arrays): Arrays to be stacked. Each array is converted
            by :func:`cupy.atleast_2d` before stacking.
        dtype (str or dtype): If provided, the destination array will have this
            dtype.
        casting ({‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optional):
            Controls what kind of data casting may occur. Defaults to
            ``'same_kind'``.

    Returns:
        cupy.ndarray: Stacked array.

    .. seealso:: :func:`numpy.dstack`

    c                 S   r'   r	   )r   
atleast_2dr!   r	   r	   r
   r#      r)   zvstack.<locals>.<listcomp>r   r   r*   )r   r   r   r	   r	   r
   vstackk   s   r0   c                   s    t  fdd| D  |||dS )uw  Stacks arrays along a new axis.

    Args:
        tup (sequence of arrays): Arrays to be stacked.
        axis (int): Axis along which the arrays are stacked.
        out (cupy.ndarray): Output array.
        dtype (str or dtype): If provided, the destination array will have this
            dtype. Cannot be provided together with ``out``.
        casting ({‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optional):
            Controls what kind of data casting may occur. Defaults to
            ``'same_kind'``.

    Returns:
        cupy.ndarray: Stacked array.

    .. seealso:: :func:`numpy.stack`
    c                    s   g | ]}t | qS r	   )r   expand_dims)r   xr   r	   r
   r#      s    zstack.<locals>.<listcomp>r   r*   r%   r	   r   r
   stack   s   r3   )r   N)r   r   r   r   r+   r.   r0   r3   r	   r	   r	   r
   <module>   s    