
    `iT.              	           d dl Z d dlZd dlZd dlmZ ddZddZ ej        dddd          Zd	 Z ej	        d
dddddd          Z
ddZej                                        d             Z	 	 ddddZ	 	 ddZdS )    N)_corec                 
   |y|                                  } t          |t          j                  r|j        t          j        k    r	| |          S t          j        | j        t                    }d||<   | |         S t          |t          j                  r-|j        t          j        k    rt          j	        | | |          S t          j        | j
        |         t                    }d||<   t          j	        || |          S )a  
    Delete values from an array along the specified axis.

    Args:
        arr (cupy.ndarray):
            Values are deleted from a copy of this array.
        indices (slice, int or array of ints):
            These indices correspond to values that will be deleted from the
            copy of `arr`.
            Boolean indices are treated as a mask of elements to remove.
        axis (int or None):
            The axis along which `indices` correspond to values that will be
            deleted. If `axis` is not given, `arr` will be flattened.

    Returns:
        cupy.ndarray:
            A copy of `arr` with values specified by `indices` deleted along
            `axis`.

    .. warning:: This function may synchronize the device.

    .. seealso:: :func:`numpy.delete`.
    NdtypeFaxis)ravel
isinstancecupyndarrayr   bool_onessizeboolcompressshape)arrindicesr   masks       q/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupy/_manipulation/add_remove.pydeleter      s    2 |iikkgt|,, 	!$*1L1Lx= y...W4y gt|,, 	;$*1L1L='3T::::y4555W}T3T2222    c                    t          j        |           } t          j        |          }|Mt          j        |                                 |                                fd                                          S t          j        | |f|          S )a  
    Append values to the end of an array.

    Args:
        arr (array_like):
            Values are appended to a copy of this array.
        values (array_like):
            These values are appended to a copy of ``arr``.  It must be of the
            correct shape (the same shape as ``arr``, excluding ``axis``).  If
            ``axis`` is not specified, ``values`` can be any shape and will be
            flattened before use.
        axis (int or None):
            The axis along which ``values`` are appended.  If ``axis`` is not
            given, both ``arr`` and ``values`` are flattened before use.

    Returns:
        cupy.ndarray:
            A copy of ``arr`` with ``values`` appended to ``axis``.  Note that
            ``append`` does not occur in-place: a new array is allocated and
            filled.  If ``axis`` is None, ``out`` is a flattened array.

    .. seealso:: :func:`numpy.append`
    Nr   )r   asarrayr   concatenate_methodr	   )r   valuesr   s      r   appendr   9   sv    2 ,s

C\&!!F|'YY[[&,,..)1. ..3egg	6#S&M4888r   zraw T x, int64 sizezT yzy = x[i % size]cupy_resizec                 ,   t          j        |           rt          j        ||           S t          j        |           } | j        dk    rt          j        || j                  S t          j        || j                  }t          | | j        |           |S )a  Return a new array with the specified shape.

    If the new array is larger than the original array, then the new
    array is filled with repeated copies of ``a``.  Note that this behavior
    is different from a.resize(new_shape) which fills with zeros instead
    of repeated copies of ``a``.

    Args:
        a (array_like): Array to be resized.
        new_shape (int or tuple of int): Shape of resized array.

    Returns:
        cupy.ndarray:
            The new array is formed from the data in the old array, repeated
            if necessary to fill out the required number of elements.  The
            data are repeated in the order that they are stored in memory.

    .. seealso:: :func:`numpy.resize`
    r   r   )
numpyisscalarr   fullr   r   zerosr   empty_resize_kernel)a	new_shapeouts      r   resizer)   a   s    ( ~a 'yA&&&QAv{{z)173333
*Y
(
(C1afc"""Jr   zT data, int64 lenzint64 yzdata == T(0) ? len : _jz	min(a, b)zy = alenfirst_nonzerofbc                 ~   | j         dk    rt          d          | j         st          d          d}| j        }|                                }d|v r't          | | j                                                  }d|v r8| j        t          | ddd         | j                                                  z
  }| ||         S )	a  Trim the leading and/or trailing zeros from a 1-D array or sequence.

    Returns the trimmed array

    Args:
        filt(cupy.ndarray): Input array
        trim(str, optional):
            'fb' default option trims the array from both sides.
            'f' option trim zeros from front.
            'b' option trim zeros from back.

    Returns:
        cupy.ndarray: trimmed input

    .. seealso:: :func:`numpy.trim_zeros`

       z'Multi-dimensional trim is not supportedz0-d array cannot be trimmedr   FBN)ndim
ValueError	TypeErrorr   upper_first_nonzero_krnlitem)filttrimstartends       r   
trim_zerosr<      s    $ y1}}BCCC9 75666E
)C::<<D
d{{#D$)4499;;
d{{i-d44R4j$)DDIIKKKc	?r   c                     t          j        t          j        |                    }t          j        | |          | d d <   d S N)r   logical_notisnanlogical_and)r   x0mask1s      r   _unique_update_mask_equal_nanrD      s8    TZ^^,,EtU++DGGGr   FT)	equal_nanc                   |t          | ||||          }|S t          j        | |d          } | j        }t          j        d|d         t          j                  }|                     |d         t          j        |dd                             } t          j	        |           } t          j
        | j        t          j                  }	t          j        |           | |	r|                     t          j                  fd}
t          j        |d         t          j                  }|                                dfg}|g k    r|                    d          \  }}|g k    r%|d         }g }g }t%          dt'          |                    D ]K} |
||         |          r|                    ||                    0|                    ||                    L|t'          |          z   }|                    ||f           |                    ||dz   f           |||<   |g k    | |         } | j        dk    r^t          j        | j        t          j                  }d|dd<   | dd         | dd         k    |dd<   t          j        |d	          }n2t          j        | j        d         t          j                  }d
|dd<   | |         }  | j        |                                                                g|dd         R  } t          j        | d|          } | f}|r|||         fz  }|rGt          j        |          dz
  }t          j        |j        t          j                  }|||<   ||fz  }|rgt          j        |          d         }t          j        |j        dz   f|j                  }||dd<   |j        |d<   ||dd         |dd         z
  fz  }t'          |          dk    r|d         }|S )a-
  Find the unique elements of an array.

    Returns the sorted unique elements of an array. There are three optional
    outputs in addition to the unique elements:

    * the indices of the input array that give the unique values
    * the indices of the unique array that reconstruct the input array
    * the number of times each unique value comes up in the input array

    Args:
        ar(array_like): Input array. This will be flattened if it is not
            already 1-D.
        return_index(bool, optional): If True, also return the indices of `ar`
            (along the specified axis, if provided, or in the flattened array)
            that result in the unique array.
        return_inverse(bool, optional): If True, also return the indices of the
            unique array (for the specified axis, if provided) that can be used
            to reconstruct `ar`.
        return_counts(bool, optional): If True, also return the number of times
            each unique item appears in `ar`.
        axis(int or None, optional): The axis to operate on. If None, ar will
            be flattened. If an integer, the subarrays indexed by the given
            axis will be flattened and treated as the elements of a 1-D array
            with the dimension of the given axis, see the notes for more
            details. The default is None.
        equal_nan(bool, optional): If True, collapse multiple NaN values in the
            return array into one.

    Returns:
        cupy.ndarray or tuple:
            If there are no optional outputs, it returns the
            :class:`cupy.ndarray` of the sorted unique values. Otherwise, it
            returns the tuple which contains the sorted unique values and
            following.

            * The indices of the first occurrences of the unique values in the
              original array. Only provided if `return_index` is True.
            * The indices to reconstruct the original array from the
              unique array. Only provided if `return_inverse` is True.
            * The number of times each of the unique values comes up in the
              original array. Only provided if `return_counts` is True.

    Notes:
       When an axis is specified the subarrays indexed by the axis are sorted.
       This is done by making the specified axis the first dimension of the
       array (move the axis to the first dimension to keep the order of the
       other axes) and then flattening the subarrays in C order.

    .. warning::

        This function may synchronize the device.

    .. seealso:: :func:`numpy.unique`
    N)return_indexreturn_inversereturn_countsrE   r   r   r.   c                     |          |         }}t          j        ||z
  d          }|j        d         dk    r&|d         }rt          j        |          rdS |dk     S dS )Nfr   TF)r   r<   r   r@   )idx1idx2leftrightcompdiffar_cmp
is_complexs         r   compare_axis_elemsz"unique.<locals>.compare_axis_elems   so    TlF4Lete|S11:a=17D dj.. t!8Our   Tr1   r   F)
_unique_1dr   moveaxisr   arangeintpreshapemathprodascontiguousarray
issubdtyper   unsignedintegeriscomplexobjastyper$   tolistpopranger*   r   r   r   anyr   sumr7   cumsumnonzero)arrG   rH   rI   r   rE   ret
orig_shapeidxis_unsignedrT   sorted_indicesqueuecurrentoffmid_elemrN   rO   ielem_posr   imaskinv_idxrg   rR   rS   s                           @@r   uniquerv      s   p |,(6'4#,. . . 
	r4	#	#B J
+aAdi
8
8
8C	JqM49Z^#<#<	=	=B			#	#B/"(D,@AAK"2&&JF &49%%      Z
1TY???NjjllAE
2++yy||b==1:q#g,,'' 	) 	)A!!'!*h77 )GAJ''''WQZ((((T?dC[!!!eX\*+++#+x % 2++( 
N	B	w{{z"($*555RaRabb6RW$QRRx1%%% y"(1+dj999QRR 
DB	DHHJJOO%%	7
122	7	7	7B	r1d	#	#B
#C %~d#$$ D!!A%*TZty999"'wx #,t$$Q'j',*,gm<<CRC)Bs122wSbS!""
3xx1}}!fJr   c                 8   t          j        |                                           } |s|r|                                 }| |         }n|                                  | }t          j        |j        t           j                  }d|d d<   |dd          |d d         k    |dd <   |r t          |dd          |d d                    ||         }|s|s|s|S |f}|r|||         fz  }|rGt          j	        |          dz
  }	t          j        |j        t           j
                  }
|	|
|<   ||
fz  }|rgt          j        |          d         }t          j        |j        dz   f|j                  }||d d<   |j        |d<   ||dd          |d d         z
  fz  }|S )Nr   Tr.   r1   r   )r   r   flattenargsortsortr$   r   r   rD   rf   rX   rg   r   r   )rh   rG   rH   rI   rE   permauxr   ri   rt   ru   rg   rk   s                r   rU   rU   G  s   	b			!	!	#	#B ~ zz||h
			:citz222DD!H122w#crc("DH :%d122hCRC999
d)C  } 

$C tDz{ D!!A%*TZty999wx #,t$$Q'j',*,gm<<CRC)Bs122wSbS!""Jr   r>   )r,   )FFFN)FFFT)r    r   rZ   r   r   r   ElementwiseKernelr%   r)   ReductionKernelr6   r<   fusionfuserD   rv   rU    r   r   <module>r      sM           +3 +3 +3 +3b9 9 9 9B )(5   < ,e+	     @ , , ,
 38%)T8<T T T T Tn 7<.2" " " " " "r   