
    `iv                     .    d dl Zd dlZddZdddddZdS )    Nc                     || j         nt          |          }|| j        nt          |          }t          j        || j        | j        |          S )ak  
    Create a view into the array with the given shape and strides.

    .. warning:: This function has to be used with extreme care, see notes.

    Parameters
    ----------
    x : ndarray
        Array to create a new.
    shape : sequence of int, optional
        The shape of the new array. Defaults to ``x.shape``.
    strides : sequence of int, optional
        The strides of the new array. Defaults to ``x.strides``.

    Returns
    -------
    view : ndarray

    See also
    --------
    numpy.lib.stride_tricks.as_strided
    reshape : reshape an array.

    Notes
    -----
    ``as_strided`` creates a view into the array given the exact strides
    and shape. This means it manipulates the internal data structure of
    ndarray and, if done incorrectly, the array elements can point to
    invalid memory and can corrupt results or crash your program.
    N)shapedtypememptrstrides)r   tupler   _cupyndarrayr   data)xr   r   s      j/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupy/lib/stride_tricks.py
as_stridedr      sT    > }AGG%,,E"?aiigG=uAG !9 9 9 9    F)subok	writeablec                    t          j        |          rt          |          n|f}|rt          d          t	          j         d|           t	          j        |          }|D ]}|dk     rt          d          |jt          t           j                            }t          |          t          |          k    r(t          dt          |           d j         d	          nzt          j
        j                            | j                  }t          |          t          |          k    r0t          d
t          |           dt          |           d           j        t           fd|D                       z   }t           j                  }t!          ||          D ]3\  }	}||	         |k     rt          d          ||	xx         |dz
  z  cc<   4t          |          |z   }
t#           ||
          S )aT	  
    Create a sliding window view into the array with the given window shape.

    Also known as rolling or moving window, the window slides across all
    dimensions of the array and extracts subsets of the array at all window
    positions.


    Parameters
    ----------
    x : array_like
        Array to create the sliding window view from.
    window_shape : int or tuple of int
        Size of window over each axis that takes part in the sliding window.
        If `axis` is not present, must have same length as the number of input
        array dimensions. Single integers `i` are treated as if they were the
        tuple `(i,)`.
    axis : int or tuple of int, optional
        Axis or axes along which the sliding window is applied.
        By default, the sliding window is applied to all axes and
        `window_shape[i]` will refer to axis `i` of `x`.
        If `axis` is given as a `tuple of int`, `window_shape[i]` will refer to
        the axis `axis[i]` of `x`.
        Single integers `i` are treated as if they were the tuple `(i,)`.
    subok : bool, optional
        If True, sub-classes will be passed-through, otherwise the returned
        array will be forced to be a base-class array (default).
    writeable : bool, optional -- not supported
        When true, allow writing to the returned view. The default is false,
        as this should be used with caution: the returned view contains the
        same memory location multiple times, so writing to one location will
        cause others to change.

    Returns
    -------
    view : ndarray
        Sliding window view of the array. The sliding window dimensions are
        inserted at the end, and the original dimensions are trimmed as
        required by the size of the sliding window.
        That is, ``view.shape = x_shape_trimmed + window_shape``, where
        ``x_shape_trimmed`` is ``x.shape`` with every entry reduced by one less
        than the corresponding window size.


    See also
    --------
    numpy.lib.stride_tricks.as_strided

    Notes
    --------
    This function is adapted from numpy.lib.stride_tricks.as_strided.

    Examples
    --------
    >>> x = _cupy.arange(6)
    >>> x.shape
    (6,)
    >>> v = sliding_window_view(x, 3)
    >>> v.shape
    (4, 3)
    >>> v
    array([[0, 1, 2],
           [1, 2, 3],
           [2, 3, 4],
           [3, 4, 5]])

    z"Writeable views are not supported.F)copyr   r   z-`window_shape` cannot contain negative valuesNzOSince axis is `None`, must provide window_shape for all dimensions of `x`; got z' window_shape elements and `x.ndim` is .z8Must provide matching length window_shape and axis; got z window_shape elements and z axes elements.c              3   2   K   | ]}j         |         V  d S N)r   ).0axr   s     r   	<genexpr>z&sliding_window_view.<locals>.<genexpr>   s)      #A#AbAIbM#A#A#A#A#A#Ar   z4window shape cannot be larger than input array shape   )r   r   )npiterabler   NotImplementedErrorr	   array
ValueErrorrangendimlen_coreinternal_normalize_axis_indicesr   listr   zipr   )r   window_shapeaxisr   r   window_shape_arraydimout_stridesx_shape_trimmedr   	out_shapes   `          r   sliding_window_viewr/   +   sh   N {<00)E,'''& 
  H!"FGGG 	AE///A\22! N N77LMMM  |U16]]##|D		)) :$'$5$5: : 12: : : ; ; ; * {#;;D!&II|D		)) H*-l*;*;H H-0YYH H H I I I )e#A#A#A#AD#A#A#AAAAK 17mmOt\** ' 'C2$$FH H HsQw&o&&5IaI>>>>r   )NNr   )cupyr	   numpyr   r   r/    r   r   <module>r3      sg           #9 #9 #9 #9Ln?#un? n? n? n? n? n? n?r   