
    `i                     N    d dl Z d dlmZ ddZd ZddZddZdd	Zd
 ZddZ	dS )    N)internalc                 0    |                      |||          S )a  Takes elements of an array at specified indices along an axis.

    This is an implementation of "fancy indexing" at single axis.

    This function does not support ``mode`` option.

    Args:
        a (cupy.ndarray): Array to extract elements.
        indices (int or array-like): Indices of elements that this function
            takes.
        axis (int): The axis along which to select indices. The flattened input
            is used by default.
        out (cupy.ndarray): Output array. If provided, it should be of
            appropriate shape and dtype.

    Returns:
        cupy.ndarray: The result of fancy indexing.

    .. seealso:: :func:`numpy.take`

    )take)aindicesaxisouts       k/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupy/_indexing/indexing.pyr   r      s    . 66'4%%%    c                    |j         j        dvrt          d          ||                                 } d}| j        }t          j        ||          }||j        k    rt          d          g }t          | j	                  D ]o\  }}||k    r|
                    |           !d|z  dz   d||z
  dz
  z  z   }|
                    t          j        |                              |                     p| t          |                   S )	aw  Take values from the input array by matching 1d index and data slices.

    Args:
        a (cupy.ndarray): Array to extract elements.
        indices (cupy.ndarray): Indices to take along each 1d slice of ``a``.
        axis (int): The axis to take 1d slices along.

    Returns:
        cupy.ndarray: The indexed result.

    .. seealso:: :func:`numpy.take_along_axis`
    )iuz"`indices` must be an integer arrayNr   z9`indices` and `a` must have the same number of dimensions)   )r   )dtypekind
IndexErrorravelndimr   _normalize_axis_index
ValueError	enumerateshapeappendcupyarangereshapetuple)r   r   r   r   fancy_indexr   n	ind_shapes           r
   take_along_axisr"      s    }++=>>>|GGII6D)$55Dw|GI I 	I K!'"" B B199w''''q5(44!8a<+@@It{1~~55i@@AAAAU;  r   raisec                 0    |                      |||          S )N)choose)r   choicesr	   modes       r
   r%   r%   G   s    88GS$'''r   c                 0    |                     | ||          S )aF  Returns selected slices of an array along given axis.

    Args:
        condition (1-D array of bools): Array that selects which entries to
            return. If len(condition) is less than the size of a along the
            given axis, then output is truncated to the length of the condition
            array.
        a (cupy.ndarray): Array from which to extract a part.
        axis (int): Axis along which to take slices. If None (default), work
            on the flattened array.
        out (cupy.ndarray): Output array. If provided, it should be of
            appropriate shape and dtype.

    Returns:
        cupy.ndarray: A copy of a without the slices along axis for which
        condition is false.

    .. warning::

            This function may synchronize the device.


    .. seealso:: :func:`numpy.compress`

    )compress)	conditionr   r   r	   s       r
   r)   r)   K   s    4 ::is+++r   r   c                 0    |                      |||          S )a  Returns specified diagonals.

    This function extracts the diagonals along two specified axes. The other
    axes are not changed. This function returns a writable view of this array
    as NumPy 1.10 will do.

    Args:
        a (cupy.ndarray): Array from which the diagonals are taken.
        offset (int): Index of the diagonals. Zero indicates the main
            diagonals, a positive value upper diagonals, and a negative value
            lower diagonals.
        axis1 (int): The first axis to take diagonals from.
        axis2 (int): The second axis to take diagonals from.

    Returns:
        cupy.ndarray: A view of the diagonals of ``a``.

    .. seealso:: :func:`numpy.diagonal`

    )diagonal)r   offsetaxis1axis2s       r
   r,   r,   h   s    , ::feU+++r   c                 Z   t          |t          j                  st          d          t          | t          j                  st          j        |           } |                                }|                                 } |                    |                                 d                   S )a  Return the elements of an array that satisfy some condition.

    This is equivalent to ``np.compress(ravel(condition), ravel(arr))``.
    If ``condition`` is boolean, ``np.extract`` is equivalent to
    ``arr[condition]``.

    Args:
        condition (int or array_like): An array whose nonzero or True entries
            indicate the elements of array to extract.
        a (cupy.ndarray): Input array of the same size as condition.

    Returns:
        cupy.ndarray: Rank 1 array of values from arr where condition is True.

    .. warning::

            This function may synchronize the device.

    .. seealso:: :func:`numpy.extract`
    z/extract requires input array to be cupy.ndarrayr   )
isinstancer   ndarray	TypeErrorarrayr   r   nonzero)r*   r   s     r
   extractr6      s    , a&& KIJJJi.. *Jy))				A!!I66)##%%a()))r   c                    t          |           t          |          k    rt          d          t          |           dk    rt          d          t          j        |          st	          d          t          t          |                    D ]s}t          ||         t          j                  st	          d          | |         }|j        j	        t          j
        ur"t          d                    |                    tt          j        | }t          j        |  } t          j        g ||R  }|d         j        dk    r| d         j        }n,t          j        | d         |d                   d         j        }t          j        ||          }t          j        ||           |ddd	         }| ddd	         } t%          ||           D ]\  }}t          j        |||
           |S )a  Return an array drawn from elements in choicelist, depending on conditions.

    Args:
        condlist (list of bool arrays): The list of conditions which determine
            from which array in `choicelist` the output elements are taken.
            When multiple conditions are satisfied, the first one encountered
            in `condlist` is used.
        choicelist (list of cupy.ndarray): The list of arrays from which the
            output elements are taken. It has to be of the same length
            as `condlist`.
        default (scalar) : If provided, will fill element inserted in `output`
            when all conditions evaluate to False. default value is 0.

    Returns:
        cupy.ndarray: The output at position m is the m-th element of the
        array in `choicelist` where the m-th element of the corresponding
        array in `condlist` is True.

    .. seealso:: :func:`numpy.select`
    z7list of cases must be same length as list of conditionsr   z3select with an empty condition list is not possiblez"default only accepts scalar valuesz.choicelist only accepts lists of cupy ndarraysz7invalid entry {} in condlist: should be boolean ndarrayNr   )where)lenr   r   isscalarr3   ranger1   r2   r   typebool_formatresult_typebroadcast_arraysr   r   emptycopytozip)	condlist
choicelistdefaultr   condr   result_shaperesultchoices	            r
   selectrL      s   , 8}}J''EG G 	G 8}}NOOO=!! ><===3z??##  *Q-66 	NLMMM{:?$*,,I   -
 j)E$h/H&<
<G<<<J!}Q{(,Xa[-7]< <<=??D 	 Ze,,FK   BFF#J"~HJ11 0 0FF$/////Mr   )NN)Nr#   )r   r   r   )r   )
r   
cupy._corer   r   r"   r%   r)   r,   r6   rL    r   r
   <module>rO      s          & & & &4%! %! %!P( ( ( (, , , ,:, , , ,2* * *D< < < < < <r   