
    `i                      R    d Z ddlZddZddZddZddZddZdd	Zdd
ZddZ	dS )z-
Functions for acting on a axis of an array.
    Nc                     t          d          g| j        z  }t          |||          ||<   | t          |                   }|S )a  Take a slice along axis 'axis' from 'a'.

    Parameters
    ----------
    a : cupy.ndarray
        The array to be sliced.
    start, stop, step : int or None
        The slice parameters.
    axis : int, optional
        The axis of `a` to be sliced.

    Examples
    --------
    >>> a = array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    >>> axis_slice(a, start=0, stop=1, axis=1)
    array([[1],
           [4],
           [7]])
    >>> axis_slice(a, start=1, axis=0)
    array([[4, 5, 6],
           [7, 8, 9]])

    Notes
    -----
    The keyword arguments start, stop and step are used by calling
    slice(start, stop, step). This implies axis_slice() does not
    handle its arguments the exactly the same as indexing. To select
    a single index k, for example, use
        axis_slice(a, start=k, stop=k+1)
    In this case, the length of the axis 'axis' in the result will
    be 1; the trivial dimension is not removed. (Use cupy.squeeze()
    to remove trivial axes.)
    Nslicendimtuple)astartstopstepaxisa_slicebs          r/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupyx/scipy/signal/_arraytools.py
axis_slicer      sC    D T{{maf$G%t,,GDM	%..AH    c                     t          d          g| j        z  }t          |||          ||<   || t          |          <   | S )ai  Take a slice along axis 'axis' from 'a' and set it to 'b' in-place.

    Parameters
    ----------
    a : numpy.ndarray
        The array to be sliced.
    b : cupy.ndarray
        The array to be assigned.
    start, stop, step : int or None
        The slice parameters.
    axis : int, optional
        The axis of `a` to be sliced.

    Examples
    --------
    >>> a = array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    >>> b1 = array([[-1], [-4], [-7]])
    >>> axis_assign(a, b1, start=0, stop=1, axis=1)
    array([[-1, 2, 3],
           [-4, 5, 6],
           [-7, 8, 9]])

    Notes
    -----
    The keyword arguments start, stop and step are used by calling
    slice(start, stop, step). This implies axis_assign() does not
    handle its arguments the exactly the same as indexing. To assign
    a single index k, for example, use
        axis_assign(a, start=k, stop=k+1)
    In this case, the length of the axis 'axis' in the result will
    be 1; the trivial dimension is not removed. (Use numpy.squeeze()
    to remove trivial axes.)

    This function works in-place and will modify the values contained in `a`
    Nr   )r	   r   r
   r   r   r   r   s          r   axis_assignr   /   sC    H T{{maf$G%t,,GDMAeGnnHr   c                 &    t          | d|          S )zeReverse the 1-D slices of `a` along axis `axis`.

    Returns axis_slice(a, step=-1, axis=axis).
    r   )r   r   )r   )r	   r   s     r   axis_reverser   Y   s    
 abt,,,,r   c                 n   |dk     r| S || j         |         dz
  k    r"t          d|| j         |         dz
  fz            t          | dd|          }t          | |dd|          }t          | d|          }t          | d|d	z    d|          }t          j        d	|z  |z
  | d	|z  |z
  f|
          }|S )a  
    Odd extension at the boundaries of an array

    Generate a new ndarray by making an odd extension of `x` along an axis.

    Parameters
    ----------
    x : ndarray
        The array to be extended.
    n : int
        The number of elements by which to extend `x` at each end of the axis.
    axis : int, optional
        The axis along which to extend `x`. Default is -1.

    Examples
    --------
    >>> from cupyx.scipy.signal._arraytools import odd_ext
    >>> a = cupy.array([[1, 2, 3, 4, 5], [0, 1, 4, 9, 16]])
    >>> odd_ext(a, 2)
    array([[-1,  0,  1,  2,  3,  4,  5,  6,  7],
           [-4, -1,  0,  1,  4,  9, 16, 23, 28]])
       XThe extension length n (%d) is too big. It must not exceed x.shape[axis]-1, which is %d.r   r
   r   r   r   r
   r   r   r   r
   r      r   shape
ValueErrorr   cupyconcatenate)xnr   left_endleft_ext	right_end	right_extexts           r   odd_extr,   a   s    . 	1uu174=1 Mqwt}q012 3 3 	3 !114888H!112DAAAH1BT222I1Bq1uXBTJJJI

AL83Q	MI57=AC C CCJr   c                    |dk     r| S || j         |         dz
  k    r"t          d|| j         |         dz
  fz            t          | |dd|          }t          | d|dz    d|          }t          j        || |f|          }|S )	a  
    Even extension at the boundaries of an array

    Generate a new ndarray by making an even extension of `x` along an axis.

    Parameters
    ----------
    x : ndarray
        The array to be extended.
    n : int
        The number of elements by which to extend `x` at each end of the axis.
    axis : int, optional
        The axis along which to extend `x`. Default is -1.

    Examples
    --------
    >>> from cupyx.scipy.signal._arraytools import even_ext
    >>> a = cupy.array([[1, 2, 3, 4, 5], [0, 1, 4, 9, 16]])
    >>> even_ext(a, 2)
    array([[ 3,  2,  1,  2,  3,  4,  5,  4,  3],
           [ 4,  1,  0,  1,  4,  9, 16,  9,  4]])

    r   r   r   r   r   r   r   r   r    )r%   r&   r   r(   r*   r+   s         r   even_extr.      s    0 	1uu174=1 Mqwt}q012 3 3 	3 !112DAAAH1Bq1uXBTJJJI

Ha3$
?
?
?CJr   c                     |dk     r| S t          | dd|          }dg| j        z  }|||<   t          j        || j                  }||z  }t          | d|          }||z  }t          j        || |f|          }	|	S )a  
    Constant extension at the boundaries of an array

    Generate a new ndarray that is a constant extension of `x` along an axis.
    The extension repeats the values at the first and last element of
    the axis.

    Parameters
    ----------
    x : ndarray
        The array to be extended.
    n : int
        The number of elements by which to extend `x` at each end of the axis.
    axis : int, optional
        The axis along which to extend `x`. Default is -1.

    Examples
    --------
    >>> from cupyx.scipy.signal._arraytools import const_ext
    >>> a = cupy.array([[1, 2, 3, 4, 5], [0, 1, 4, 9, 16]])
    >>> const_ext(a, 2)
    array([[ 1,  1,  1,  2,  3,  4,  5,  5,  5],
           [ 0,  0,  0,  1,  4,  9, 16, 16, 16]])
    r   r   r   dtyper   r   r   )r   r   r#   onesr1   r$   )
r%   r&   r   r'   
ones_shaper2   r(   r)   r*   r+   s
             r   	const_extr4      s    2 	1uu!114888HqvJJt9Zqw///DhH1BT222Iy I

Ha3$
?
?
?CJr   c                     |dk     r| S t          | j                  }|||<   t          j        || j                  }t          j        || |f|          }|S )a  
    Zero padding at the boundaries of an array

    Generate a new ndarray that is a zero-padded extension of `x` along
    an axis.

    Parameters
    ----------
    x : ndarray
        The array to be extended.
    n : int
        The number of elements by which to extend `x` at each end of the
        axis.
    axis : int, optional
        The axis along which to extend `x`. Default is -1.

    Examples
    --------
    >>> from cupyx.scipy.signal._arraytools import zero_ext
    >>> a = cupy.array([[1, 2, 3, 4, 5], [0, 1, 4, 9, 16]])
    >>> zero_ext(a, 2)
    array([[ 0,  0,  1,  2,  3,  4,  5,  0,  0],
           [ 0,  0,  0,  1,  4,  9, 16,  0,  0]])
    r   r0   r   )listr!   r#   zerosr1   r$   )r%   r&   r   zeros_shaper7   r+   s         r   zero_extr9      s`    2 	1uuqw--KKJ{!'222E

E1e,4
8
8
8CJr   c                     || j         nt          |          }|| j        nt          |          }t          j        || j        | j        |          S )a  
    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

    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)r!   r1   memptrstrides)r!   r   r<   r#   ndarrayr1   data)r%   r!   r<   s      r   _as_stridedr?      sX    2 }AGG%,,E"?aiigG<17167D D D Dr   )NNNr   )r   )NN)
__doc__r#   r   r   r   r,   r.   r4   r9   r?    r   r   <module>rB      s     % % % %P' ' ' 'T- - - -# # # #L! ! ! !H# # # #L   DD D D D D Dr   