
    
9j                    b    S SK Jr  S SKrS SKJr  SS jrS rSS jrSS jrSS jr	S	 r
SS
 jrg)    )annotationsN)internalc                &    U R                  XU5      $ )aj  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       Q/home/wildlama/miniconda3/lib/python3.13/site-packages/cupy/_indexing/indexing.pyr   r      s    . 66'%%    c                   UR                   R                  S;  a  [        S5      eUc  U R                  5       n SnU R                  n[
        R                  " X#5      nX1R                  :w  a  [        S5      e/ n[        U R                  5       Hd  u  pVXR:X  a  UR                  U5        M  SU-  S-   SX5-
  S-
  -  -   nUR                  [        R                  " U5      R                  U5      5        Mf     U [        U5         $ )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 arrayr   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     }}+=>>|GGI66D))$5D||GI 	I K!''"9w'q5(448a<+@@It{{1~55i@A # U;  r   c                &    U R                  XU5      $ )N)choose)r   choicesr
   modes       r   r%   r%   I   s    88G$''r   c                &    UR                  XU5      $ )a  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)   M   s    4 ::is++r   c                &    U R                  XU5      $ )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,   j   s    , ::fU++r   c                D   [        U[        R                  5      (       d  [        S5      e[        U [        R                  5      (       d  [        R                  " U 5      n UR                  5       nU R                  5       n UR                  U R                  5       S   5      $ )aS  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      st    , a&&IJJi..JJy)			A!I66)##%a())r   c                   [        U 5      [        U5      :w  a  [        S5      e[        U 5      S:X  a  [        S5      e[        R                  " U5      (       d  [	        S5      e[        [        U5      5       Ht  n[        X   [        R                  5      (       d  [	        S5      eX   nUR                  R                  [        R                  Ld  M\  [        SR                  U5      5      e   [        R                  " U6 n[        R                  " U 6 n [        R                  " / UQUP76 nUS   R                  S:X  a  U S   R                  nO*[        R                  " U S   US   5      S   R                  n[        R                   " Xe5      n[        R"                  " Xr5        USSS	2   nU SSS	2   n [%        X5       H  u  p[        R"                  " XxUS
9  M     U$ )aZ  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 8}NOO==!!<==3z?#*-66LMM{::??$**,I  $ j)E$$h/H&&<
<G<J!}Q{((,,Xa[-7]<<=??Du 	 ZZ,FKK BFF#J"~HJ1F$/ 2 Mr   )NN)Nraise)r   r   r   )r   )
__future__r   r   
cupy._corer   r   r#   r%   r)   r,   r6   rL    r   r   <module>rQ      s3    "  &4%!P(,:,2*D<r   