
    Vpf                       d dl mZ d dlmZmZ d dlmZ d dlZd dlZd dl	Z	d dl
Zd dlZd dlZd dlm
Z d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZmZ d dlmZ d dlm Z m!Z! d dl"m#Z#m$Z$m%Z% 	 	 dbdcdZ&dddZ'dedZ(	 	 dfdgdZ)	 	 dhdid$Z*	 	 dfdgd%Z+	 	 dhdid&Z,	 	 djdkd0Z-dld:Z.dmdnd<Z/	 	 	 	 	 	 	 dodpdPZ0	 	 	 	 dqdrdTZ1	 	 	 	 	 dsdtdXZ2	 	 	 	 	 dsdudYZ3dvd[Z4	 	 	 	 	 dwdxdaZ5dS )y    )annotations)CallableSequence)partialN)lax)_ensure_index_tuple)dtypes)PrecisionLike)linalg)check_arraylikepromote_dtypes_inexactpromote_dtypes_complex)signal_helper)Array	ArrayLike)canonicalize_axistuple_deletetuple_insertfullin1r   in2modestraxesSequence[int] | Nonereturnr   c                    t          d            t                     \    j        j        k    rt          d          |dvrt          d          t	          t
          |          }| |           S t          |          }t           fd|D                       }t          t           j                            t          |          z
  }t           fd|D                       r"t          d	 j        d
j        d|          t          |          D ]}t          j        |||          } |           S )a&  
  Convolve two N-dimensional arrays using Fast Fourier Transform (FFT).

  JAX implementation of :func:`scipy.signal.fftconvolve`.

  Args:
    in1: left-hand input to the convolution.
    in2: right-hand input to the convolution. Must have ``in1.ndim == in2.ndim``.
    mode: controls the size of the output. Available operations are:

      * ``"full"``: (default) output the full convolution of the inputs.
      * ``"same"``: return a centered portion of the ``"full"`` output which
        is the same size as ``in1``.
      * ``"valid"``: return the portion of the ``"full"`` output which do not
        depend on padding at the array edges.

    axes: optional sequence of axes along which to apply the convolution.

  Returns:
    Array containing the convolved result.

  See Also:
    - :func:`jax.numpy.convolve`: 1D convolution
    - :func:`jax.scipy.signal.convolve`: direct convolution

  Examples:
    A few 1D convolution examples. Because FFT-based convolution is approximate,
    We use :func:`jax.numpy.printoptions` below to adjust the printing precision:

    >>> x = jnp.array([1, 2, 3, 2, 1])
    >>> y = jnp.array([1, 1, 1])

    Full convolution uses implicit zero-padding at the edges:

    >>> with jax.numpy.printoptions(precision=3):
    ...   print(jax.scipy.signal.fftconvolve(x, y, mode='full'))
    [1. 3. 6. 7. 6. 3. 1.]

    Specifying ``mode = 'same'`` returns a centered convolution the same size
    as the first input:

    >>> with jax.numpy.printoptions(precision=3):
    ...   print(jax.scipy.signal.fftconvolve(x, y, mode='same'))
    [3. 6. 7. 6. 3.]

    Specifying ``mode = 'valid'`` returns only the portion where the two arrays
    fully overlap:

    >>> with jax.numpy.printoptions(precision=3):
    ...   print(jax.scipy.signal.fftconvolve(x, y, mode='valid'))
    [6. 7. 6.]
  fftconvolvez/in1 and in2 should have the same dimensionality)samer   validz-mode must be one of ['same', 'full', 'valid']r   Nc              3  B   K   | ]}t          |j                  V  d S N)r   ndim).0axr   s     U/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/scipy/signal.py	<genexpr>zfftconvolve.<locals>.<genexpr>h   s0      >>2 SX..>>>>>>    c              3  P   K   | ] }j         |         j         |         k    V  !d S r#   shape)r%   ir   r   s     r'   r(   zfftconvolve.<locals>.<genexpr>j   s4      ;;!11	%;;;;;;r)   z0mapped axes must have same shape; got in1.shape=z in2.shape=z axes=)in_axesout_axes)r   r   r$   
ValueErrorr   _fftconvolve_unbatchedr   tuplesetrangeanyr,   sortedjaxvmap)r   r   r   r   _fftconvolvemapped_axesr&   s   ``     r'   r   r   (   sv   l -c***#C--(#sX
F
G
GG	***
D
E
EE/d;;;,	\<S!!!	T	"	"$	>>>>>>>	>	>$E#(OO$$s4yy0+;;;;;{;;;;; a
_ci__39__X\__
`
``; C Cb8L"rBBBLL	c3		r)   c                   t          d t          | j        |j                  D                       }|}|dk    r{t          d t          | j        |j                  D                       }t          d t          | j        |j                  D                       }|s|st	          d          |r|| }} t          j        |           r#t
          j        j        t
          j        j	        }}n"t
          j        j
        t
          j        j        }} || |          }	 |||          }
 ||	|
z  |          }|dk    r|}nX|dk    r| j        }nJ|dk    r2t          d t          | j        |j                  D                       }nt	          d	|          t          d
 t          ||          D                       }t          j        |||          S )Nc              3  ,   K   | ]\  }}||z   d z
  V  dS    N r%   s1s2s      r'   r(   z)_fftconvolve_unbatched.<locals>.<genexpr>q   s.      IIVRR"Wq[IIIIIIr)   r    c              3  (   K   | ]\  }}||k    V  d S r#   r?   r@   s      r'   r(   z)_fftconvolve_unbatched.<locals>.<genexpr>w   s*      CCvr2"(CCCCCCr)   c              3  (   K   | ]\  }}||k    V  d S r#   r?   r@   s      r'   r(   z)_fftconvolve_unbatched.<locals>.<genexpr>x   s*      @@FBrRx@@@@@@r)   zVFor 'valid' mode, One input must be at least as large as the other in every dimension.r   r   c              3  ,   K   | ]\  }}||z
  d z   V  dS r=   r?   r@   s      r'   r(   z)_fftconvolve_unbatched.<locals>.<genexpr>   s.      JJfb"b2gkJJJJJJr)   zUnrecognized mode=c              3  ,   K   | ]\  }}||z
  d z  V  dS )   Nr?   )r%   	full_sizeout_sizes      r'   r(   z)_fftconvolve_unbatched.<locals>.<genexpr>   sL       O O/Ix #X-!3 O O O O O Or)   )r2   zipr,   allr0   jnpiscomplexobjfftfftnifftnrfftnirfftnr   dynamic_slice)r   r   r   
full_shape	fft_shapeno_swapswaprN   ifftsp1sp2conv	out_shapestart_indicess                 r'   r1   r1   p   s   IIs39ci/H/HIIIII* )	W__CCSY	)B)BCCCCCG@@c#)SY&?&?@@@@@D At A @ A A A c3cc .cgmCCsw~CC#C#	cCi	#	#$	V^^IIv~~	IIwJJCIsy0I0IJJJJJII
,T,,
-
-- O O36z93M3MO O O O O-		4		:	::r)   	precisionr
   c               J   |dvrt          d          | j        |j        k    rt          d          | j        dk    s|j        dk    r t          d| j         d|j         d          t	          | |          \  } }t          d t          | j        |j                  D                       }t          d	 t          | j        |j                  D                       }|s|st          d
          |j        }|r|| }} |j        }t          j        |          }|dk    rd |D             }n3|dk    rd t          ||          D             }n|dk    rd |D             }t          d |D                       }	t          j        | d         |d         |	||          }
|
d         S )N)r   r   r    z-mode must be one of ['full', 'same', 'valid']z3in1 and in2 must have the same number of dimensionsr   z;zero-size arrays not supported in convolutions, got shapes z and .c              3  (   K   | ]\  }}||k    V  d S r#   r?   r@   s      r'   r(   z_convolve_nd.<locals>.<genexpr>   s*      AAVRbAAAAAAr)   c              3  (   K   | ]\  }}||k    V  d S r#   r?   r@   s      r'   r(   z_convolve_nd.<locals>.<genexpr>   *      >>&"bR2X>>>>>>r)   z<One input must be smaller than the other in every dimension.r    c                    g | ]}d S r   r   r?   r%   ss     r'   
<listcomp>z _convolve_nd.<locals>.<listcomp>   s    %%%!v%%%r)   r   c                L    g | ]!\  }}|d z
  |d z
  dz  z
  ||z
  |d z
  dz  z   f"S )r>   rG   r?   )r%   rh   s_os      r'   ri   z _convolve_nd.<locals>.<listcomp>   sS     4 4 4As AqQ&C37q.(@A 4 4 4r)   r   c                "    g | ]}|d z
  |d z
  fS r>   r?   rg   s     r'   ri   z _convolve_nd.<locals>.<listcomp>   s$    ---!Aq1u~---r)   c              3     K   | ]}d V  dS r=   r?   rg   s     r'   r(   z_convolve_nd.<locals>.<genexpr>   s"      ##!######r)   )NNr^   rf   )r0   r$   sizer,   r   rK   rJ   rL   flipr2   r   conv_general_dilated)r   r   r   r^   rV   rW   shape_or,   paddingstridesresults              r'   _convolve_ndrw      s   	***
D
E
EEX
J
K
KKX]]ch!mm
oSVS\oocfclooo
p
pp#C--(#sAAs39ci'@'@AAAAA'	>>C	39$=$=>>>	>	>$
 UT U
S
T
TTI'	 CC
)%#	W__%%u%%%GGv~~4 4"5'224 4 4GGv~~--u---G##U#####'#C
OS_g$+yB B B&	r)   automethodc                    |dk    rt          | ||          S |dv rt          | |||          S t          d|d          )a  Convolution of two N-dimensional arrays.

  JAX implementation of :func:`scipy.signal.convolve`.

  Args:
    in1: left-hand input to the convolution.
    in2: right-hand input to the convolution. Must have ``in1.ndim == in2.ndim``.
    mode: controls the size of the output. Available operations are:

      * ``"full"``: (default) output the full convolution of the inputs.
      * ``"same"``: return a centered portion of the ``"full"`` output which
        is the same size as ``in1``.
      * ``"valid"``: return the portion of the ``"full"`` output which do not
        depend on padding at the array edges.

    method: controls the computation method. Options are

      * ``"auto"``: (default) always uses the ``"direct"`` method.
      * ``"direct"``: lower to :func:`jax.lax.conv_general_dilated`.
      * ``"fft"``: compute the result via a fast Fourier transform.

    precision: Specify the precision of the computation. Refer to
      :class:`jax.lax.Precision` for a description of available values.

  Returns:
    Array containing the convolved result.

  See Also:
    - :func:`jax.numpy.convolve`: 1D convolution
    - :func:`jax.scipy.signal.convolve2d`: 2D convolution
    - :func:`jax.scipy.signal.correlate`: ND correlation

  Examples:
    A few 1D convolution examples:

    >>> x = jnp.array([1, 2, 3, 2, 1])
    >>> y = jnp.array([1, 1, 1])

    Full convolution uses implicit zero-padding at the edges:

    >>> jax.scipy.signal.convolve(x, y, mode='full')
    Array([1., 3., 6., 7., 6., 3., 1.], dtype=float32)

    Specifying ``mode = 'same'`` returns a centered convolution the same size
    as the first input:

    >>> jax.scipy.signal.convolve(x, y, mode='same')
    Array([3., 6., 7., 6., 3.], dtype=float32)

    Specifying ``mode = 'valid'`` returns only the portion where the two arrays
    fully overlap:

    >>> jax.scipy.signal.convolve(x, y, mode='valid')
    Array([6., 7., 6.], dtype=float32)
  rN   r!   )directrx   ro   zGot method=z&; expected 'auto', 'fft', or 'direct'.)r   rw   r0   r   r   r   ry   r^   s        r'   convolver}      s`    r u__sCd++++###S$)<<<<
KFKKK
L
LLr)   fillboundary	fillvaluefloatc                    |dk    s|dk    rt          d          t          j        |           dk    st          j        |          dk    rt          d          t	          | |||          S )a	  Convolution of two 2-dimensional arrays.

  JAX implementation of :func:`scipy.signal.convolve2d`.

  Args:
    in1: left-hand input to the convolution. Must have ``in1.ndim == 2``.
    in2: right-hand input to the convolution. Must have ``in2.ndim == 2``.
    mode: controls the size of the output. Available operations are:

      * ``"full"``: (default) output the full convolution of the inputs.
      * ``"same"``: return a centered portion of the ``"full"`` output which
        is the same size as ``in1``.
      * ``"valid"``: return the portion of the ``"full"`` output which do not
        depend on padding at the array edges.

    boundary: only ``"fill"`` is supported.
    fillvalue: only ``0`` is supported.
    method: controls the computation method. Options are

      * ``"auto"``: (default) always uses the ``"direct"`` method.
      * ``"direct"``: lower to :func:`jax.lax.conv_general_dilated`.
      * ``"fft"``: compute the result via a fast Fourier transform.

    precision: Specify the precision of the computation. Refer to
      :class:`jax.lax.Precision` for a description of available values.

  Returns:
    Array containing the convolved result.

  See Also:
    - :func:`jax.numpy.convolve`: 1D convolution
    - :func:`jax.scipy.signal.convolve`: ND convolution
    - :func:`jax.scipy.signal.correlate`: ND correlation

  Examples:
    A few 2D convolution examples:

    >>> x = jnp.array([[1, 2],
    ...                [3, 4]])
    >>> y = jnp.array([[2, 1, 1],
    ...                [4, 3, 4],
    ...                [1, 3, 2]])

    Full 2D convolution uses implicit zero-padding at the edges:

    >>> jax.scipy.signal.convolve2d(x, y, mode='full')
    Array([[ 2.,  5.,  3.,  2.],
           [10., 22., 17., 12.],
           [13., 30., 32., 20.],
           [ 3., 13., 18.,  8.]], dtype=float32)

    Specifying ``mode = 'same'`` returns a centered 2D convolution of the same size
    as the first input:

    >>> jax.scipy.signal.convolve2d(x, y, mode='same')
    Array([[22., 17.],
           [30., 32.]], dtype=float32)

    Specifying ``mode = 'valid'`` returns only the portion of 2D convolution
    where the two arrays fully overlap:

    >>> jax.scipy.signal.convolve2d(x, y, mode='valid')
    Array([[22., 17.],
           [30., 32.]], dtype=float32)
  r~   r   z7convolve2d() only supports boundary='fill', fillvalue=0rG   z0convolve2d() only supports 2-dimensional inputs.ro   )NotImplementedErrorrL   r$   r0   rw   )r   r   r   r   r   r^   s         r'   
convolve2dr      sr    F 9>>
W
X
XXXc]]a38C==A--
G
H
HH	c3		:	:	::r)   c                r    t          | t          j        |                                          |||          S )a  Cross-correlation of two N-dimensional arrays.

  JAX implementation of :func:`scipy.signal.correlate`.

  Args:
    in1: left-hand input to the cross-correlation.
    in2: right-hand input to the cross-correlation. Must have ``in1.ndim == in2.ndim``.
    mode: controls the size of the output. Available operations are:

      * ``"full"``: (default) output the full cross-correlation of the inputs.
      * ``"same"``: return a centered portion of the ``"full"`` output which
        is the same size as ``in1``.
      * ``"valid"``: return the portion of the ``"full"`` output which do not
        depend on padding at the array edges.

    method: controls the computation method. Options are

      * ``"auto"``: (default) always uses the ``"direct"`` method.
      * ``"direct"``: lower to :func:`jax.lax.conv_general_dilated`.
      * ``"fft"``: compute the result via a fast Fourier transform.

    precision: Specify the precision of the computation. Refer to
      :class:`jax.lax.Precision` for a description of available values.

  Returns:
    Array containing the cross-correlation result.

  See Also:
    - :func:`jax.numpy.correlate`: 1D cross-correlation
    - :func:`jax.scipy.signal.correlate2d`: 2D cross-correlation
    - :func:`jax.scipy.signal.convolve`: ND convolution

  Examples:
    A few 1D correlation examples:

    >>> x = jnp.array([1, 2, 3, 2, 1])
    >>> y = jnp.array([1, 3, 2])

    Full 1D correlation uses implicit zero-padding at the edges:

    >>> jax.scipy.signal.correlate(x, y, mode='full')
    Array([ 2.,  7., 13., 15., 11.,  5.,  1.], dtype=float32)

    Specifying ``mode = 'same'`` returns a centered 1D correlation of the same
    size as the first input:

    >>> jax.scipy.signal.correlate(x, y, mode='same')
    Array([ 7., 13., 15., 11.,  5.], dtype=float32)

    Specifying ``mode = 'valid'`` returns only the portion of 1D correlation
    where the two arrays fully overlap:

    >>> jax.scipy.signal.correlate(x, y, mode='valid')
    Array([13., 15., 11.], dtype=float32)
  )r^   ry   )r}   rL   rq   conjr|   s        r'   	correlater   E  s0    r 
#sx

++TYv	V	V	VVr)   c                   |dk    s|dk    rt          d          t          j        |           dk    st          j        |          dk    rt          d          t	          d t          | j        |j                  D                       }t	          d t          | j        |j                  D                       }|dk    rOt          j        |           |                                }} t          j        t          | |||	                    }n1|d
k    r|r>|s<t          j        |          |                                 }} t          | |||	          }nt          j        |           |                                }} t          j        t          | |||	                    }n|rNt          j        |          |                                 }} t          | |||	                                          }nMt          j        |           |                                }} t          j        t          | |||	                    }|S )aX	  Cross-correlation of two 2-dimensional arrays.

  JAX implementation of :func:`scipy.signal.correlate2d`.

  Args:
    in1: left-hand input to the cross-correlation. Must have ``in1.ndim == 2``.
    in2: right-hand input to the cross-correlation. Must have ``in2.ndim == 2``.
    mode: controls the size of the output. Available operations are:

      * ``"full"``: (default) output the full cross-correlation of the inputs.
      * ``"same"``: return a centered portion of the ``"full"`` output which
        is the same size as ``in1``.
      * ``"valid"``: return the portion of the ``"full"`` output which do not
        depend on padding at the array edges.

    boundary: only ``"fill"`` is supported.
    fillvalue: only ``0`` is supported.
    method: controls the computation method. Options are

      * ``"auto"``: (default) always uses the ``"direct"`` method.
      * ``"direct"``: lower to :func:`jax.lax.conv_general_dilated`.
      * ``"fft"``: compute the result via a fast Fourier transform.

    precision: Specify the precision of the computation. Refer to
      :class:`jax.lax.Precision` for a description of available values.

  Returns:
    Array containing the cross-correlation result.

  See Also:
    - :func:`jax.numpy.correlate`: 1D cross-correlation
    - :func:`jax.scipy.signal.correlate`: ND cross-correlation
    - :func:`jax.scipy.signal.convolve`: ND convolution

  Examples:
    A few 2D correlation examples:

    >>> x = jnp.array([[2, 1, 3],
    ...                [1, 3, 1],
    ...                [4, 1, 2]])
    >>> y = jnp.array([[1, 3],
    ...                [4, 2]])

    Full 2D correlation uses implicit zero-padding at the edges:

    >>> jax.scipy.signal.correlate2d(x, y, mode='full')
    Array([[ 4., 10., 10., 12.],
           [ 8., 15., 24.,  7.],
           [11., 28., 14.,  9.],
           [12.,  7.,  7.,  2.]], dtype=float32)

    Specifying ``mode = 'same'`` returns a centered 2D correlation of the same
    size as the first input:

    >>> jax.scipy.signal.correlate2d(x, y, mode='same')
    Array([[15., 24.,  7.],
           [28., 14.,  9.],
           [ 7.,  7.,  2.]], dtype=float32)

    Specifying ``mode = 'valid'`` returns only the portion of 2D correlation
    where the two arrays fully overlap:

    >>> jax.scipy.signal.correlate2d(x, y, mode='valid')
    Array([[15., 24.],
           [28., 14.]], dtype=float32)
  r~   r   z8correlate2d() only supports boundary='fill', fillvalue=0rG   z1correlate2d() only supports 2-dimensional inputs.c              3  (   K   | ]\  }}||k    V  d S r#   r?   r@   s      r'   r(   zcorrelate2d.<locals>.<genexpr>  rc   r)   c              3  (   K   | ]\  }}||k    V  d S r#   r?   r@   s      r'   r(   zcorrelate2d.<locals>.<genexpr>  s*      EERB"HEEEEEEr)   r   ro   r    )
r   rL   r$   r0   rK   rJ   r,   rq   r   rw   )	r   r   r   r   r   r^   rW   
same_shaperv   s	            r'   correlate2dr     s   H 9>>
X
Y
YYXc]]a38C==A--
H
I
II	>>C	39$=$=>>>	>	>$EE3sy#)+D+DEEEEE*	V^^x}}chhjjCXl3TYGGGHHFFw KJ K#

3cCdi@@@ff#

3cxS#tyIIIJJff K#

3cCdi@@@EEGGff#

3cxS#tyIIIJJf	-r)   lineardataaxisinttypebpoverwrite_dataNonec           	        |t          d          |dvrt          d          t          t          j        |                     \  }|dk    r||                    |d          z
  S |j        |         }t          j        t          j	        t          j
        d||f                             }|d         dk     s|d	         |k    rt          d
          t          j        ||d          }|j        }|                    |d	          }t          t          |          dz
            D ]}	||	dz            ||	         z
  }
t          j        t          j        |
|j                  t          j        d|
dz   |j                  |
                    |j                  z  g          j        }t+          ||	         ||	dz                      }t-          j        |||                   ^}}|j        |                             t          j        ||t6          j        j                             }t          j        |                    |          d|          S )a  
  Remove linear or piecewise linear trends from data.

  JAX implementation of :func:`scipy.signal.detrend`.

  Args:
    data: The input array containing the data to detrend.
    axis: The axis along which to detrend. Default is -1 (the last axis).
    type: The type of detrending. Can be:

      * ``'linear'``: Fit a single linear trend for the entire data.
      * ``'constant'``: Remove the mean value of the data.

    bp: A sequence of breakpoints. If given, piecewise linear trends
      are fit between these breakpoints.
    overwrite_data: This argument is not supported by JAX's implementation.

  Returns:
    The detrended data array.

  Examples:
    A simple detrend operation in one dimension:

    >>> data = jnp.array([1., 4., 8., 8., 9.])

    Removing a linear trend from the data:

    >>> detrended = jax.scipy.signal.detrend(data)
    >>> with jnp.printoptions(precision=3, suppress=True):  # suppress float error
    ...   print("Detrended:", detrended)
    ...   print("Underlying trend:", data - detrended)
    Detrended: [-1. -0.  2. -0. -1.]
    Underlying trend: [ 2.  4.  6.  8. 10.]

    Removing a constant trend from the data:

    >>> detrended = jax.scipy.signal.detrend(data, type='constant')
    >>> with jnp.printoptions(precision=3):  # suppress float error
    ...   print("Detrended:", detrended)
    ...   print("Underlying trend:", data - detrended)
    Detrended: [-5. -2.  2.  2.  3.]
    Underlying trend: [6. 6. 6. 6. 6.]
  Nz(overwrite_data argument not implemented.)constantr   z*Trend type must be 'linear' or 'constant'.r   T)keepdimsr   r   zOBreakpoints must be non-negative and less than length of data along given axis.r>   dtypero   )r   r0   r   rL   asarraymeanr,   npsortuniquer_moveaxisreshaper4   lenvstackonesr   arangeastypeTslicer   lstsqataddmatmulr   	PrecisionHIGHEST)r   r   r   r   r   data_arrNbp_arrr,   mNptsAslcoef_s                  r'   detrendr     s    Z 
H
I
II	'''
A
B
BB$S[%6%677)(	ZhmmD4m8888tAWRYruQAX//00Fay1}}r
Qhiii|HdA..HNE2&&H3v;;?## \ \AE]VAY&d
*X^,,,
1dQhhn555HN8S8SS 	 	 
  F1q5M**ba"..hdQR$$cjDCMDY&Z&Z&Z%Z[[hh<((//D999r)   xwindetrend_funcCallable[[Array], Array]npersegnoverlapnfft
int | Nonesidesc                   | j         j        dk    r|                     |j                   } | j        ^ }}|dk    r|dk    r| dt          j        f         }	n||z
  }
t          |          }|                     t          j	        |          |df          } t          j                            | |f|
fdd          }	 |	j        g ||	j        dd	         R  }	 ||	          }	t          j        |          rt          |	          \  }	|                    d
t!          |          z  d|fz             |	z  }	|dk    r&t          j        j                            |	|          S t          j        j                            |	j        |          S )zBCalculate windowed FFT in the same way the original SciPy does.
  r-   r>   r   .VALID)NTCOITr   )dimension_numbersNrm   twosided)n)r   kindr   r,   r   newaxislistr   mathprodr7   r   conv_general_dilated_patchesrL   rM   r   r   numpyrN   rfftreal)r   r   r   r   r   r   r   batch_shapesignal_lengthrv   steps              r'   _fft_helperr   *  s    W\S	A !;\\h!mmsBJFFXD{##K			49[))=!<==AW11	G:w/ 2 1 1F V^=[=6<+<===F <& 	c -$V,,GF;;tc+...!W=>>G& j9=Vt,,,9=fkT222r)   r   c                   |dk     r| S || j         |         dz
  k    r$t          d| d| j         |         dz
   d          t          j        | dd|          }t	          j        t          j        | d|dz   |          |          }t          j        | dd|          }t	          j        t          j        | |dz    d|          |          }t	          j        d	|z  |z
  | d	|z  |z
  f|          }|S )
a  Extends `x` along with `axis` by odd-extension.

  This function was previously a part of "scipy.signal.signaltools" but is no
  longer exposed.

  Args:
    x : input array
    n : the number of points to be added to the both end
    axis: the axis to be extended
  r>   zThe extension length n (z;) is too big. It must not exceed x.shape[axis]-1, which is r`   r   r   r   NrG   )r,   r0   r   slice_in_dimrL   rq   concatenate)r   r   r   left_endleft_ext	right_end	right_extexts           r'   odd_extr   N  s@    UUH	
	M1 	M 	M898I	M 	M 	MN N N aAD111(Xc&q!QU>>>TJJJ(q"d666)hs'QU8RdCCC$OOO)X0Y24 #	$ 	$ 	$# 
*r)         ?hannr   TdensitypsdFyArrayLike | Nonefswindowdetrend_type%bool | str | Callable[[Array], Array]return_onesidedboolscaling
str | Nonepaddedtuple[Array, Array, Array]c           
     r  
 |dvrt          d| d          d } |d          t           |d           |dd	          d
 d}||vr4t          d| dt          |                                                     t          j                            t          j        
d          
t          
| j
                  
|9t          d|            t          |           \  } | }t          | j        
          }n|dk    rt          d          t          d| |           t          | |          \  } }| j
        |j
        k    rt          d          	 t          j        t          | j        
          t          |j        
                    }n"# t           $ r}t          d          |d}~ww xY wt#          j        | j                  }t)          j        |          j        }d}d}d}|;t          j                            t,          |d          }|dk     rt          d          t/          j        |||n|| j        
         | j                  \  }}||dz  }n&t          j                            t,          |d          }||}n&t          j                            t,          |d          }|Y| j        dk    rMt          j        | j        |          t          j        | j        |          t          j        | j        |          fS n| j        dk    s|j        dk    rst7          |t9          | j        
         |j        
                   
          }t          j        ||          t          j        ||          t          j        ||          fS t          j        | 
d          } |!|j
        dk    rt          j        |
d          }|| j        d         |j        d         k    r| j        d         |j        d         k     r^t          | j                  }|j        d         | j        d         z
  |d<   t          j        | t          j        | |          fd          } n]t          |j                  }| j        d         |j        d         z
  |d<   t          j        |t          j        | |          fd          }||k     rt          d          ||k    rt          d           ||z
  }|,||         } || |dz  d!          } | |||dz  d!          }|r| j        d         |z
   |z  |z  }t          j        | t          j        | g | j        dd         |R           fd!          } |>t          j        |t          j        | g |j        dd         |R           fd!          }sd" }n6tA                    stC          tD          d#          }n
dk    r
fd$}n}|	d%k    rd&|||z  #                                z  z  }n3|	d'k    rd&|#                                dz  z  }nt          d(|	           |d)k    rt          j$        |          }tK          |          \  }|rAd*} t          j&        |           st          j&        |          rd+} tO          j(        d,           nd+} | d+k    r+t          j)        j*        +                    |d|z  |-          }!n0| d*k    r*t          j)        j*        ,                    |d|z  |-          }!t[          | ||||||           }"|-t[          |||||||           }#t          j.        |"          |#z  }"n|dk    rt          j.        |"          |"z  }"|"|z  }"| d*k    r3|dk    r-|dz  rdnd}$|"j/        d.d|$f         0                    d          }"t          j1        |dz  | j        d         |dz  z
  dz   ||z
  |-          |z  }%||%|dz  |z  z  }%|"2                    |          }"||d)k    r|"j3        }"t          j        |"d
          }"|!|%|"fS )/a3  LAX-backend implementation of `scipy.signal._spectral_helper`.

  Unlike the original helper function, `y` can be None for explicitly
  indicating auto-spectral (non cross-spectral) computation.  In addition to
  this, `detrend` argument is renamed to `detrend_type` for avoiding internal
  name overlap.
  )r   stftzUnknown value for mode z!, must be one of: ('psd', 'stft')c                     d fd	}|S )Nr   c                v    d t          | j                  D             }||f||<   t          j        | |fi S )Nc                    g | ]}d S re   r?   )r%   unused_ns     r'   ri   zC_spectral_helper.<locals>.make_pad.<locals>.pad.<locals>.<listcomp>~  s    888h6888r)   )r4   r$   rL   pad)r   r   r   	pad_widthkwargsr   s       r'   r   z/_spectral_helper.<locals>.make_pad.<locals>.pad}  sG    88%--888iAioWQ	4226222r)   r   r?   )r   r   r   s   `` r'   make_padz"_spectral_helper.<locals>.make_pad|  s.    3 3 3 3 3 3 3 Jr)   reflectedger   g        )constant_valuesc                    | S r#   r?   )r   argsr   s      r'   <lambda>z"_spectral_helper.<locals>.<lambda>  s    q r)   )evenoddr   zerosNzUnknown boundary option 'z', must be one of: zaxis of windowed-FFTNspectral_helperr   z4two-argument mode is available only when mode=='psd'z=two-arguments must have the same rank ({x.ndim} vs {y.ndim}).z%x and y cannot be broadcast together.r   znperseg of windowed-FFTr>   "nperseg must be a positive integer)input_lengthr   rG   znoverlap of windowed-FFTznfft of windowed-FFTr   r+   z.nfft must be greater than or equal to nperseg.#noverlap must be less than nperseg.r   c                    | S r#   r?   )ds    r'   r  z"_spectral_helper.<locals>.<lambda>  s    Q r)   )r   r   c                r    t          j        | d          }  |           } t          j        | d          S )Nr   )rL   r   )r  r   r   s    r'   r   z&_spectral_helper.<locals>.detrend_func  s7    
,q$
#
#a
,q//a\!R&&&r)   r   r   spectrumzUnknown scaling: r   onesidedr   z9Input data is complex, switching to return_onesided=Falser   .)4r0   r   r   keysr7   coreconcrete_or_erroroperatorindexr   r$   r   r   r   r,   rL   broadcast_shapesr	   to_complex_dtyper   r   finfor   r   _triage_segmentsrp   r  r   minr   r   
zeros_likecallabler   r   sumsqrtr   rM   warningswarnr   rN   fftfreqrfftfreqr   	conjugater   mulr   r   r   )&r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   boundary_funcsy_arr
outershapeerrresult_dtype
freq_dtypenperseg_intnfft_intnoverlap_intr   r,   	pad_shapenstepext_funcnaddr   scaler   freqsrv   result_yendtimes&          `  `                           r'   _spectral_helperr5  j  sI	    
  
 7t 7 7 7 8 8 8   hy!!(6""x
C888(( . ^##
	9H 	9 	9 3 3 5 566	9 	9: : : 
	#	#HND$:
< 
<$	4	(	($Y%q)))		"	"BAEagt,,JJu}}MNNN%q!,,,%a++HAuvVWWWI'QWd(C(C(4U[$(G(GI Ijj I I I>??SHI (11,x%%+*+(,(,,S'-FH HKQ;<<<"3ggk74=1 1 1#{ !#LL8--c8.HJ JL 
\HHx))#t*@B BH Yv{{Yqw
++SYqw
-K-KSYWXW^`lMmMmmm  	v{{ejAoo:s174=%+d:K'L'LdSSeYuj))39UJ+G+GSXZfIgIggg 
l1dB!]uzA~~Lb))E ]qwr{ek"o55wr{U[_$$qw--ik"o3im
/1cnQi@@@A2
F
Faau{##igbkEKO3imoucnQi&H&H&HI2NNe
E
F
FF[  
:
;
;;

$% h'HK1$2...A}hukQ.R888e d gbk+%&.+=DCN14Iagcrcl4ID4I4IJJJKRTUUUA}oucnQ>WCRC@P>WRV>W>W&X&X&XY`bccce 
  ;LLL!! 
 7B???LLrzz' ' ' ' ' ' '
  L 	2s)))*EE*#''))Q,EE
222
3
33	V^^HUOOE!%((&%  E
 -c.q11 -em , - - - E
jIM!!(AbD
!CCEE
IM""8QrT"DDE q#|"L(EC C& ]5#|&hG GH]6""X-FFu}}]6""V+FE/&
jTU]]Q,
&$$BCYsAcEz"&&q))F	K!OQWR[;?%BQ%F,.j
B 
B 
BDF
G$[1_""D==&&& Y46>>[F <D))&	f	s   ;F 
F/F**F/   r  r   c                <    t          | d|||||||d|
d||	          S )a  
  Compute the short-time Fourier transform (STFT).

  JAX implementation of :func:`scipy.signal.stft`.

  Args:
    x: Array representing a time series of input values.
    fs: Sampling frequency of the time series (default: 1.0).
    window: Data tapering window to apply to each segment. Can be a window function name,
      a tuple specifying a window length and function, or an array (default: ``'hann'``).
    nperseg: Length of each segment (default: 256).
    noverlap: Number of points to overlap between segments (default: ``nperseg // 2``).
    nfft: Length of the FFT used, if a zero-padded FFT is desired. If ``None`` (default),
      the FFT length is ``nperseg``.
    detrend: Specifies how to detrend each segment. Can be ``False`` (default: no detrending),
      ``'constant'`` (remove mean), ``'linear'`` (remove linear trend), or a callable
      accepting a segment and returning a detrended segment.
    return_onesided: If True (default), return a one-sided spectrum for real inputs.
      If False, return a two-sided spectrum.
    boundary: Specifies whether the input signal is extended at both ends, and how.
      Options are ``None`` (no extension), ``'zeros'`` (default), ``'even'``, ``'odd'``,
      or ``'constant'``.
    padded: Specifies whether the input signal is zero-padded at the end to make its
      length a multiple of `nperseg`. If True (default), the padded signal length is
      the next multiple of ``nperseg``.
    axis: Axis along which the STFT is computed; the default is over the last axis (-1).

  Returns:
    A length-3 tuple of arrays ``(f, t, Zxx)``. ``f`` is the Array of sample frequencies.
    ``t`` is the Array of segment times, and ``Zxx`` is the STFT of ``x``.

  See Also:
    :func:`jax.scipy.signal.istft`: inverse short-time Fourier transform.
  Nr  r   )r   r   r   r   r   )r5  )r   r   r   r   r   r   r   r   r   r   r   s              r'   r   r   ?  s<    L 
!T2vw",4%!'	
) 
) 
) )r)   r   averagetuple[Array, Array]c                   t          | |||||||||	|
d          \  }}}||dz   }|j        dk    r0|j        dk    r$|j        d         dk    r|d	k    rt	          j        |j        d                                       |j                  }t          j	        |          rUt          j
        t          j        |          d
          dt          j
        t          j        |          d
          z  z   }nt          j
        |d
          }||z  }nQ|dk    r|                    d
          }n4t          d|           t          j        ||j        dd                   }||fS )aM	  
  Estimate cross power spectral density (CSD) using Welch's method.

  This is a JAX implementation of :func:`scipy.signal.csd`. It is similar to
  :func:`jax.scipy.signal.welch`, but it operates on two input signals and
  estimates their cross-spectral density instead of the power spectral density
  (PSD).

  Args:
    x: Array representing a time series of input values.
    y: Array representing the second time series of input values, the same length as ``x``
      along the specified ``axis``. If not specified, then assume ``y = x`` and compute
      the PSD ``Pxx`` of ``x`` via Welch's  method.
    fs: Sampling frequency of the inputs (default: 1.0).
    window: Data tapering window to apply to each segment. Can be a window function name,
      a tuple specifying a window length and function, or an array (default: ``'hann'``).
    nperseg: Length of each segment (default: 256).
    noverlap: Number of points to overlap between segments (default: ``nperseg // 2``).
    nfft: Length of the FFT used, if a zero-padded FFT is desired. If ``None`` (default),
      the FFT length is ``nperseg``.
    detrend: Specifies how to detrend each segment. Can be ``False`` (default: no detrending),
      ``'constant'`` (remove mean), ``'linear'`` (remove linear trend), or a callable
      accepting a segment and returning a detrended segment.
    return_onesided: If True (default), return a one-sided spectrum for real inputs.
      If False, return a two-sided spectrum.
    scaling: Selects between computing the power spectral density (``'density'``, default)
      or the power spectrum (``'spectrum'``)
    axis: Axis along which the CSD is computed (default: -1).
    average: The type of averaging to use on the periodograms; one of ``'mean'`` (default)
      or ``'median'``.

  Returns:
    A length-2 tuple of arrays ``(f, Pxy)``. ``f`` is the array of sample frequencies,
    and ``Pxy`` is the cross spectral density of `x` and `y`

  Notes:
    The original SciPy function exhibits slightly different behavior between
    ``csd(x, x)`` and ``csd(x, x.copy())``.  The LAX-backend version is designed
    to follow the latter behavior.  To replicate the former, call this function
    function as ``csd(x, None)``.

  See Also:
    - :func:`jax.scipy.signal.welch`: Power spectral density.
    - :func:`jax.scipy.signal.stft`: Short-time Fourier transform.
  r   r!   Ny                rG   r   r   r>   medianr   y              ?r   z(average must be "median" or "mean", got )r5  r$   rp   r,   r   _median_biasr   r   rL   rM   r;  r   imagr   r0   r   )r   r   r   r   r   r   r   r   r   r   r   r8  r1  r   Pxybiass                   r'   csdr@  l  st   d #1aVWh")?GT',. . .-%C ]
(C 	X]]sx!||
y}q	H		)#)B-88??	JJC   	)CHSMM333CHSMM;;;;<## 
3R(((#tfhhBhMGMMNNNKSYss^,,c	r)   c                P    t          | d|||||||||	|
          \  }}||j        fS )aE  
  Estimate power spectral density (PSD) using Welch's method.

  This is a JAX implementation of :func:`scipy.signal.welch`. It divides the
  input signal into overlapping segments, computes the modified periodogram for
  each segment, and averages the results to obtain a smoother estimate of the PSD.

  Args:
    x: Array representing a time series of input values.
    fs: Sampling frequency of the inputs (default: 1.0).
    window: Data tapering window to apply to each segment. Can be a window function name,
      a tuple specifying a window length and function, or an array (default: ``'hann'``).
    nperseg: Length of each segment (default: 256).
    noverlap: Number of points to overlap between segments (default: ``nperseg // 2``).
    nfft: Length of the FFT used, if a zero-padded FFT is desired. If ``None`` (default),
      the FFT length is ``nperseg``.
    detrend: Specifies how to detrend each segment. Can be ``False`` (default: no detrending),
      ``'constant'`` (remove mean), ``'linear'`` (remove linear trend), or a callable
      accepting a segment and returning a detrended segment.
    return_onesided: If True (default), return a one-sided spectrum for real inputs.
      If False, return a two-sided spectrum.
    scaling: Selects between computing the power spectral density (``'density'``, default)
      or the power spectrum (``'spectrum'``)
    axis: Axis along which the PSD is computed (default: -1).
    average: The type of averaging to use on the periodograms; one of ``'mean'`` (default)
      or ``'median'``.

  Returns:
    A length-2 tuple of arrays ``(f, Pxx)``. ``f`` is the array of sample frequencies,
    and ``Pxx`` is the power spectral density of ``x``.

  See Also:
    - :func:`jax.scipy.signal.csd`: Cross power spectral density.
    - :func:`jax.scipy.signal.stft`: Short-time Fourier transform.
  N)
r   r   r   r   r   r   r   r   r   r8  )r@  r   )r   r   r   r   r   r   r   r   r   r   r8  r1  Pxxs                r'   welchrC    sF    P 1dr&'$4#2Gg/ / /*%
 
r)   	step_sizec                L   t          d|            t          j                            t          |d          }| j        dk     rt          d          | j        ^ }}}t          j	        |          }| 
                    |||f          } ||dz
  z  |z   }d|dz
  |z  z   }||z  }t          j        | ddd||z
  ff          } | 
                    ||||f          } |                     d          } t          j        | ddd|fdf          } | j        d         dz
  }	| 
                    |d	f          } | d
d
d
||	z  |z  f         } | 
                    |||	|z  f          } |                     d          d
d
d
|f         } | 
                    t          |          dz             S )a4  Utility function compatible with tf.signal.overlap_and_add.

  Args:
    x: An array with `(..., frames, frame_length)`-shape.
    step_size: An integer denoting overlap offsets. Must be less than
      `frame_length`.

  Returns:
    An array with `(..., output_size)`-shape containing overlapped signal.
  _overlap_and_addzstep_size for overlap_and_addrG   z2Input must have (..., frames, frame_length) shape.r>   rf   r   )r   rG   r>      r   Nr   r   )r   r7   r  r  r   r$   r0   r,   r   r   r   rL   r   	transposer  r2   )
r   rD  r   nframessegment_lenflat_batchsizeoutput_sizenstep_per_segmentpadded_segment_lenshrinkeds
             r'   rF  rF    s    $a(((h((i(GI I)VaZZ
I
J
JJ'(w$;9[)).ii+677!Wq[)K7+;?y88 )94	ga&&1&8;&F"GHII!ii*;YGHH! kk,!	ga&&1g,788!WQZ!^(ii$%%!6)I5667!ii!2Hy4HIJJ! eeemmAAA||O$!	
5%%-	.	..r)   r   Zxxinput_onesided	time_axis	freq_axisc
           	     B
  	 t          d|            | j        dk     rt          d          t          	| j                  	t          | j                  	k    rt          d          t	          j        | t          j                            t          j
        | t          j                                      } |rd| j        	         dz
  z  n| j        	         }
t          j                            t          |p|
d          }|dk     rt          d          d	}||
}|r||
dz   k    r|dz  }n&t          j                            t          |d          }||k     rt          d| d| d          t          j                            t          |p|dz  d          }||k    rt          d          ||z
  }| j        dz
  k    s	| j        dz
  k    rHt!          	fdt#          | j                  D                       }t	          j        | |	fz             } |rt          j        j        j        nt          j        j        j        } || d|          dd
|d
d
f         }|dk    rm|dk    rt	          j        dg          n6t	          j        t	          j        d	t          j        |d                    dz  }|                    |j                  }nt;          |t<          t           f          rU	 d	dlm } n%# tB          $ r}tC          d|          |d
}~ww xY w |||          }t	          j        ||j                  }n^t	          j        |          }tE          |j                  dk    rt          d          |j        d	         |k    rt          d|           ||#                                z  }tI          j%        |g t#          |j        dz
            dR           }tM          ||z  '                    dd          |          }t	          j(        ||z  |j        d         d          }tM          |'                    dd          |          }|r&|d|dz  |dz   f         }|d|dz  |dz   f         }|t	          j)        |dk    |d          z  }|j        dk    r/| j        dz
  k    r!	k     rdz  t	          j*        |d          }t	          j+        |j        d	         t          j,        |j                  j                  |z  }||fS ) a7  
  Perform the inverse short-time Fourier transform (ISTFT).

  JAX implementation of :func:`scipy.signal.istft`; computes the inverse of
  :func:`jax.scipy.signal.stft`.

  Args:
    Zxx: STFT of the signal to be reconstructed.
    fs: Sampling frequency of the time series (default: 1.0)
    window: Data tapering window to apply to each segment. Can be a window function name,
      a tuple specifying a window length and function, or an array (default: ``'hann'``).
    nperseg: Number of data points per segment in the STFT. If ``None`` (default), the
      value is determined from the size of ``Zxx``.
    noverlap: Number of points to overlap between segments (default: ``nperseg // 2``).
    nfft: Number of FFT points used in the STFT. If ``None`` (default), the
      value is determined from the size of ``Zxx``.
    input_onesided: If Tru` (default), interpret the input as a one-sided STFT
      (positive frequencies only). If False, interpret the input as a two-sided STFT.
    boundary: If True (default), it is assumed that the input signal was extended at
      its boundaries by ``stft``. If `False`, the input signal is assumed to have been truncated at the boundaries by `stft`.
    time_axis: Axis in `Zxx` corresponding to time segments (default: -1).
    freq_axis: Axis in `Zxx` corresponding to frequency bins (default: -2).

  Returns:
    A length-2 tuple of arrays ``(t, x)``. ``t`` is the Array of signal times, and ``x``
    is the reconstructed time series.

  See Also:
    :func:`jax.scipy.signal.stft`: short-time Fourier transform.

  Examples:
    Demonstrate that this gives the inverse of :func:`~jax.scipy.signal.stft`:

    >>> x = jnp.array([1., 2., 3., 2., 1., 0., 1., 2.])
    >>> f, t, Zxx = jax.scipy.signal.stft(x, nperseg=4)
    >>> print(Zxx)  # doctest: +SKIP
    [[ 1. +0.j   2.5+0.j   1. +0.j   1. +0.j   0.5+0.j ]
     [-0.5+0.5j -1.5+0.j  -0.5-0.5j -0.5+0.5j  0. -0.5j]
     [ 0. +0.j   0.5+0.j   0. +0.j   0. +0.j  -0.5+0.j ]]
    >>> t, x_reconstructed = jax.scipy.signal.istft(Zxx)
    >>> print(x_reconstructed)
    [1. 2. 3. 2. 1. 0. 1. 2.]
  istftrG   zInput stft must be at least 2d!z/Must specify differing time and frequency axes!r   r>   znperseg: segment length of STFTr  r   Nznfft of STFTzFFT length (z) must be longer than nperseg (z).znoverlap of STFTr	  c              3  (   K   | ]}|hv|V  d S r#   r?   )r%   idxrS  rR  s     r'   r(   zistft.<locals>.<genexpr>p  s?       M M#i5K*K*K*K*K*K*KM Mr)   r   )r   r   .r   r   F)endpoint)
get_windowz&scipy must be available to use window=zwindow must be 1-Dzwindow must have length of r   r   g|=)-r   r$   r0   r   rL   r   r7   r	   canonicalize_dtyper   result_type	complex64r,   r  r  r   r2   r4   rH  r   rN   irfftrX   arraysinlinspacepir   r   
isinstancer   scipy.signalrY  ImportErrorr   r  r   expand_dimsrF  swapaxesrepeatwherer   r   r  )rP  r   r   r   r   r   rQ  r   rR  rS  	n_defaultr)  r*  r+  r-  
outer_idxsifuncxsubsr   rY  r&  r   win_squarednormr4  s           ``               r'   rU  rU    s   b '3X\\
6
7
77	3844)	3844))
F
G
GGCsz<<nS",'' )  ) 	* 	* 	*# 2@ )qCIi(1,--Ii(  **30D9+LN N+1__
9
:
::(	\H +Q66!mhx))#t^DDH
OxOOOOOQ Q Q ++C1M[A=M,>@ @,[  
:
;
;;

$% #(Q,)sx!|";"; M M M M MSXM M M M MJ
-Z9i*@@
A
AC "0
G#)-

SY]5G%
%"
%
%
%c<K<&:
;% v)Q..#)SE


CGCLCFT_jo<p<p<p4q4quv4vC
**U[
!
!CC&3,'' DN))))))) N N NC&CCDD#MN
*V[
)
)C
)Cu{
+
+
+CC
+f

C
39~~+,,,
y|{""B[BBCCC37799% 	9uUZ!^449b99::#--b"55u==!
C#IBbAAA+	+..r266	>	>$  7	#{A~Q//
/0A[!^k1n$5556DsytS)))! VaZZCHqL  	Y		Q	
,q"i
(
(a	AGAJbhqw&7&7&=	>	>	>	C$	q.s   6K= =
LLL)r   N)
r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )
r   r   r   r   r   r   r^   r
   r   r   )r   rx   N)r   r   r   r   r   r   ry   r   r^   r
   r   r   )r   r~   r   N)r   r   r   r   r   r   r   r   r   r   r^   r
   r   r   )r   r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   NNNr   Tr   r   r   NF)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )
r   r   r6  NNFTr  Tr   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )
r   r   NNNr   Tr   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r8  r   r   r9  )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r8  r   r   r9  )r   r   rD  r   r   r   )	r   r   NNNTTr   r   )rP  r   r   r   r   r   r   r   r   r   r   r   rQ  r   r   r   rR  r   rS  r   r   r9  )6
__future__r   collections.abcr   r   	functoolsr   r   r  r  r   r   r7   jax.numpy.fft	jax.numpyrL   r   jax._src.api_utilr   jax._srcr	   jax._src.lax.laxr
   jax._src.numpyr   jax._src.numpy.utilr   r   r   jax._src.third_party.scipyr   jax._src.typingr   r   jax._src.utilr   r   r   r   r1   rw   r}   r   r   r   r   r   r   r5  r   r@  rC  rF  rU  r?   r)   r'   <module>r|     s   # " " " " " . . . . . . . .              



                 1 1 1 1 1 1       * * * * * * ! ! ! ! ! !E E E E E E E E E E 4 4 4 4 4 4 , , , , , , , , G G G G G G G G G G =C-1F  F  F  F  F P"; "; "; ";P   D HN(,>M >M >M >M >MB LR@DG; G; G; G; G;T IO)-9W 9W 9W 9W 9Wx MSAE] ] ] ] ]@ NO#'F: F: F: F: F:R!3 !3 !3 !3H    8 EHAEEIKUBKOS$)R R R R Rj NQ9=U\*,*) *) *) *) *)Z KQ;?0:5>'-	J J J J JZ 8>=A2<7@)/	- - - - -`-/ -/ -/ -/` :@=A:>24	I I I I I I Ir)   