
    _Mhf                      J    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S )z-
Functions for acting on a axis of an array.
    Nc                     t          d          g| j        z  }t          |||          ||<   | t          |                   }|S )a0  Take a slice along axis 'axis' from 'a'.

    Parameters
    ----------
    a : numpy.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
    --------
    >>> import numpy as np
    >>> from scipy.signal._arraytools import axis_slice
    >>> a = np.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 numpy.squeeze()
    to remove trivial axes.)
    N)slicendimtuple)astartstopstepaxisa_slicebs          X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/scipy/signal/_arraytools.py
axis_slicer      sC    H T{{maf$G%t,,GDM	%..AH    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   1   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 )aL  
    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
    --------
    >>> import numpy as np
    >>> from scipy.signal._arraytools import odd_ext
    >>> a = np.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]])

    Odd extension is a "180 degree rotation" at the endpoints of the original
    array:

    >>> t = np.linspace(0, 1.5, 100)
    >>> a = 0.9 * np.sin(2 * np.pi * t**2)
    >>> b = odd_ext(a, 40)
    >>> import matplotlib.pyplot as plt
    >>> plt.plot(np.arange(-40, 140), b, 'b', lw=1, label='odd extension')
    >>> plt.plot(np.arange(100), a, 'r', lw=2, label='original')
    >>> plt.legend(loc='best')
    >>> plt.show()
       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   npconcatenate)xnr   left_endleft_ext	right_end	right_extexts           r   odd_extr)   9   s    H 	1uu174=1 Lqwt}q012 3 3 	3 !114888H!112DAAAH1BT222I1Bq1uXBTJJJI
.!h,1i-)35 #$ $ $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 )	aI  
    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
    --------
    >>> import numpy as np
    >>> from scipy.signal._arraytools import even_ext
    >>> a = np.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]])

    Even extension is a "mirror image" at the boundaries of the original array:

    >>> t = np.linspace(0, 1.5, 100)
    >>> a = 0.9 * np.sin(2 * np.pi * t**2)
    >>> b = even_ext(a, 40)
    >>> import matplotlib.pyplot as plt
    >>> plt.plot(np.arange(-40, 140), b, 'b', lw=1, label='even extension')
    >>> plt.plot(np.arange(100), a, 'r', lw=2, label='original')
    >>> plt.legend(loc='best')
    >>> plt.show()
    r   r   r   r   r   r   r   r   r   )r"   r#   r   r%   r'   r(   s         r   even_extr+   n   s    F 	1uu174=1 Lqwt}q012 3 3 	3 !112DAAAH1Bq1uXBTJJJI
.(#% #$ $ $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
    --------
    >>> import numpy as np
    >>> from scipy.signal._arraytools import const_ext
    >>> a = np.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]])

    Constant extension continues with the same values as the endpoints of the
    array:

    >>> t = np.linspace(0, 1.5, 100)
    >>> a = 0.9 * np.sin(2 * np.pi * t**2)
    >>> b = const_ext(a, 40)
    >>> import matplotlib.pyplot as plt
    >>> plt.plot(np.arange(-40, 140), b, 'b', lw=1, label='constant extension')
    >>> plt.plot(np.arange(100), a, 'r', lw=2, label='original')
    >>> plt.legend(loc='best')
    >>> plt.show()
    r   r   r   dtyper   r   r   )r   r   r    onesr.   r!   )
r"   r#   r   r$   
ones_shaper/   r%   r&   r'   r(   s
             r   	const_extr1      s    N 	1uu!114888HqvJJt7:QW---DhH1BT222Iy I
.(#% #$ $ $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
    --------
    >>> import numpy as np
    >>> from scipy.signal._arraytools import zero_ext
    >>> a = np.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   r-   r   )listr   r    zerosr.   r!   )r"   r#   r   zeros_shaper4   r(   s         r   zero_extr6      s_    4 	1uuqw--KKH[000E
.%E*
6
6
6CJr   Tc                     | |st          d          n2t          j        |           st          d          t          |           } | S )z
    Check if the given sampling frequency is a scalar and raises an exception
    otherwise. If allow_none is False, also raises an exception for none
    sampling rates. Returns the sampling frequency as float or none if the
    input is none.
    Nz#Sampling frequency can not be none.z.Sampling frequency fs must be a single scalar.)r   r    isscalarfloat)fs
allow_nones     r   _validate_fsr<      sY     
z 	DBCCC	D {2 	OMNNN2YYIr   )NNNr   )r   )T)
__doc__numpyr    r   r   r)   r+   r1   r6   r<    r   r   <module>r@      s        ' ' ' 'T- - - -2 2 2 2j/ / / /d4 4 4 4n       F     r   