
    tKgx7                         d Z g dZddlmZmZmZmZmZmZm	Z	m
Z
 ddlmZ ddlmZ i ZddefdZ[i Zdefd	Z[i Zdefd
Z[i ZefdZ[d Zi ZdefdZ[i ZdefdZ[i ZdefdZ[i ZdefdZ[i ZdefdZ[y)z1
Differential and pseudo-differential operators.
)
difftilbertitilberthilbertihilbertcs_diffcc_diffsc_diffss_diffshift    )piasarraysincossinhcoshtanhiscomplexobj   )convolve)_datacopiedNc                    t        |       }|dk(  r|S t        |      r2t        |j                  ||      dt        |j                  ||      z  z   S |dt
        z  |z  }nd}t        |       }|j                  |||f      }|Jt        |      dkD  r|r|j                          |r||fd}t        j                  |||d      }|||||f<   t        ||       }	t        j                  |||dz  |		      S )
a*  
    Return kth derivative (or integral) of a periodic sequence x.

    If x_j and y_j are Fourier coefficients of periodic functions x
    and y, respectively, then::

      y_j = pow(sqrt(-1)*j*2*pi/period, order) * x_j
      y_0 = 0 if order is not 0.

    Parameters
    ----------
    x : array_like
        Input array.
    order : int, optional
        The order of differentiation. Default order is 1. If order is
        negative, then integration is carried out under the assumption
        that ``x_0 == 0``.
    period : float, optional
        The assumed period of the sequence. Default is ``2*pi``.

    Notes
    -----
    If ``sum(x, axis=0) = 0`` then ``diff(diff(x, k), -k) == x`` (within
    numerical accuracy).

    For odd order and even ``len(x)``, the Nyquist mode is taken zero.

    r                 ?         ?   c                 &    | rt        || z  |      S yNr   )pow)kordercs      _/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/scipy/fftpack/_pseudo_diffs.pykernelzdiff.<locals>.kernelA   s    1Q3u~%    r   dzero_nyquistswap_real_imagoverwrite_x)r   r   r   realimagr   lengetpopitemr   init_convolution_kernelr   )
xr!   period_cachetmpr"   nomegar$   r+   s
             r#   r   r      s   : !*Cz
CCHHU6*2d388E&.I+IIIbDKAAJJ%{#E}v;   !1 	 006E>?A#%{c1%KSeai)46 6r%   c                    t        |       }t        |      r2t        |j                  ||      dt        |j                  ||      z  z   S ||dz  t
        z  |z  }t        |       }|j                  ||f      }|Gt        |      dkD  r|r|j                          |r|fd}t        j                  ||d      }||||f<   t        ||       }t        j                  ||d|      S )a  
    Return h-Tilbert transform of a periodic sequence x.

    If x_j and y_j are Fourier coefficients of periodic functions x
    and y, respectively, then::

        y_j = sqrt(-1)*coth(j*h*2*pi/period) * x_j
        y_0 = 0

    Parameters
    ----------
    x : array_like
        The input array to transform.
    h : float
        Defines the parameter of the Tilbert transform.
    period : float, optional
        The assumed period of the sequence. Default period is ``2*pi``.

    Returns
    -------
    tilbert : ndarray
        The result of the transform.

    Notes
    -----
    If ``sum(x, axis=0) == 0`` and ``n = len(x)`` is odd, then
    ``tilbert(itilbert(x)) == x``.

    If ``2 * pi * h / period`` is approximately 10 or larger, then
    numerically ``tilbert == hilbert``
    (theoretically oo-Tilbert == Hilbert).

    For even ``len(x)``, the Nyquist mode of ``x`` is taken zero.

    r   r   r   c                 *    | rdt        || z        z  S y)Nr   r   r   r    hs     r#   r$   ztilbert.<locals>.kernel   s    4!9}$r%   r   r'   r)   )r   r   r   r,   r-   r   r.   r/   r0   r   r1   r   	r2   r<   r3   r4   r5   r6   r7   r$   r+   s	            r#   r   r   S   s    H !*CCsxxF+GCHHa001 	1 EBJAAJJ1vE}v;    	 00Fa@!uc1%KSaKPPr%   c                    t        |       }t        |      r2t        |j                  ||      dt        |j                  ||      z  z   S ||dz  t
        z  |z  }t        |       }|j                  ||f      }|Gt        |      dkD  r|r|j                          |r|fd}t        j                  ||d      }||||f<   t        ||       }t        j                  ||d|      S )a  
    Return inverse h-Tilbert transform of a periodic sequence x.

    If ``x_j`` and ``y_j`` are Fourier coefficients of periodic functions x
    and y, respectively, then::

      y_j = -sqrt(-1)*tanh(j*h*2*pi/period) * x_j
      y_0 = 0

    For more details, see `tilbert`.

    r   r   r   c                 &    | rt        || z         S yr   r:   r;   s     r#   r$   zitilbert.<locals>.kernel   s    QqS	z!r%   r   r=   r)   )r   r   r   r,   r-   r   r.   r/   r0   r   r1   r   r>   s	            r#   r   r      s     !*CC6*(388Af--. 	.aCF6MAAJJ!uE}v;    	 006A>!uc1%KSaKPPr%   c                    t        |       }t        |      r.t        |j                        dt        |j                        z  z   S t        |       }|j                  |      }|Ct        |      dkD  r|r|j                          |rd }t        j                  ||d      }|||<   t        ||       }t        j                  ||d|      S )a  
    Return Hilbert transform of a periodic sequence x.

    If x_j and y_j are Fourier coefficients of periodic functions x
    and y, respectively, then::

      y_j = sqrt(-1)*sign(j) * x_j
      y_0 = 0

    Parameters
    ----------
    x : array_like
        The input array, should be periodic.
    _cache : dict, optional
        Dictionary that contains the kernel used to do a convolution with.

    Returns
    -------
    y : ndarray
        The transformed input.

    See Also
    --------
    scipy.signal.hilbert : Compute the analytic signal, using the Hilbert
                           transform.

    Notes
    -----
    If ``sum(x, axis=0) == 0`` then ``hilbert(ihilbert(x)) == x``.

    For even len(x), the Nyquist mode of x is taken zero.

    The sign of the returned transform does not have a factor -1 that is more
    often than not found in the definition of the Hilbert transform. Note also
    that `scipy.signal.hilbert` does have an extra -1 factor compared to this
    function.

    r   r   c                     | dkD  ry| dk  ryy)Nr   r   g      g         )r    s    r#   r$   zhilbert.<locals>.kernel   s    1uQr%   r   r=   r)   )r   r   r   r,   r-   r.   r/   r0   r   r1   r   )r2   r4   r5   r6   r7   r$   r+   s          r#   r   r      s    N !*CCsxx GCHH$5!555AAJJqME}v;  	 006A>q	c1%KSaKPPr%   c                     t        |        S )z
    Return inverse Hilbert transform of a periodic sequence x.

    If ``x_j`` and ``y_j`` are Fourier coefficients of periodic functions x
    and y, respectively, then::

      y_j = -sqrt(-1)*sign(j) * x_j
      y_0 = 0

    )r   )r2   s    r#   r   r     s     AJ;r%   c                    t        |       }t        |      r4t        |j                  |||      dt        |j                  |||      z  z   S ||dz  t
        z  |z  }|dz  t
        z  |z  }t        |       }|j                  |||f      }|It        |      dkD  r|r|j                          |r||fd}t        j                  ||d      }|||||f<   t        ||       }	t        j                  ||d|	      S )a  
    Return (a,b)-cosh/sinh pseudo-derivative of a periodic sequence.

    If ``x_j`` and ``y_j`` are Fourier coefficients of periodic functions x
    and y, respectively, then::

      y_j = -sqrt(-1)*cosh(j*a*2*pi/period)/sinh(j*b*2*pi/period) * x_j
      y_0 = 0

    Parameters
    ----------
    x : array_like
        The array to take the pseudo-derivative from.
    a, b : float
        Defines the parameters of the cosh/sinh pseudo-differential
        operator.
    period : float, optional
        The period of the sequence. Default period is ``2*pi``.

    Returns
    -------
    cs_diff : ndarray
        Pseudo-derivative of periodic sequence `x`.

    Notes
    -----
    For even len(`x`), the Nyquist mode of `x` is taken as zero.

    r   r   r   c                 D    | rt        || z         t        || z        z  S yr   )r   r   r    abs      r#   r$   zcs_diff.<locals>.kernel@  s%    QqS	z$qs)++r%   r   r=   r)   )r   r   r   r,   r-   r   r.   r/   r0   r   r1   r   
r2   rH   rI   r3   r4   r5   r6   r7   r$   r+   s
             r#   r   r     s   < !*CCsxx!F+'#((1Qv../ 	/aCF6MaCF6MAAJJ!AwE}v;   1 	 006A>!Awc1%KSaKPPr%   c                    t        |       }t        |      r4t        |j                  |||      dt        |j                  |||      z  z   S ||dz  t
        z  |z  }|dz  t
        z  |z  }t        |       }|j                  |||f      }|It        |      dkD  r|r|j                          |r||fd}t        j                  ||d      }|||||f<   t        ||       }	t        j                  ||d|	      S )a  
    Return (a,b)-sinh/cosh pseudo-derivative of a periodic sequence x.

    If x_j and y_j are Fourier coefficients of periodic functions x
    and y, respectively, then::

      y_j = sqrt(-1)*sinh(j*a*2*pi/period)/cosh(j*b*2*pi/period) * x_j
      y_0 = 0

    Parameters
    ----------
    x : array_like
        Input array.
    a,b : float
        Defines the parameters of the sinh/cosh pseudo-differential
        operator.
    period : float, optional
        The period of the sequence x. Default is 2*pi.

    Notes
    -----
    ``sc_diff(cs_diff(x,a,b),b,a) == x``
    For even ``len(x)``, the Nyquist mode of x is taken as zero.

    r   r   r   c                 B    | rt        || z        t        || z        z  S yr   )r   r   rG   s      r#   r$   zsc_diff.<locals>.kernelx  s#    AaCyac**r%   r   r=   r)   )r   r   r	   r,   r-   r   r.   r/   r0   r   r1   r   rJ   s
             r#   r	   r	   P  s   4 !*CCsxx!F+'#((1Qv../ 	/aCF6MaCF6MAAJJ!AwE}v;   1 	 006A>!Awc1%KSaKPPr%   c                    t        |       }t        |      r4t        |j                  |||      dt        |j                  |||      z  z   S ||dz  t
        z  |z  }|dz  t
        z  |z  }t        |       }|j                  |||f      }|Gt        |      dkD  r|r|j                          |r||fd}t        j                  ||      }|||||f<   t        ||       }	t        j                  |||	      S )ac  
    Return (a,b)-sinh/sinh pseudo-derivative of a periodic sequence x.

    If x_j and y_j are Fourier coefficients of periodic functions x
    and y, respectively, then::

      y_j = sinh(j*a*2*pi/period)/sinh(j*b*2*pi/period) * x_j
      y_0 = a/b * x_0

    Parameters
    ----------
    x : array_like
        The array to take the pseudo-derivative from.
    a,b
        Defines the parameters of the sinh/sinh pseudo-differential
        operator.
    period : float, optional
        The period of the sequence x. Default is ``2*pi``.

    Notes
    -----
    ``ss_diff(ss_diff(x,a,b),b,a) == x``

    r   r   r   c                 \    | rt        || z        t        || z        z  S t        |      |z  S N)r   floatrG   s      r#   r$   zss_diff.<locals>.kernel  s.    AaCyac**8A:r%   r+   )r   r   r
   r,   r-   r   r.   r/   r0   r   r1   r   rJ   s
             r#   r
   r
     s    2 !*CCsxx!F+'#((1Qv../ 	/aCF6MaCF6MAAJJ!AwE}v;   1 	 006:!Awc1%KS;??r%   c                    t        |       }t        |      r4t        |j                  |||      dt        |j                  |||      z  z   S ||dz  t
        z  |z  }|dz  t
        z  |z  }t        |       }|j                  |||f      }|Gt        |      dkD  r|r|j                          |r||fd}t        j                  ||      }|||||f<   t        ||       }	t        j                  |||	      S )a  
    Return (a,b)-cosh/cosh pseudo-derivative of a periodic sequence.

    If x_j and y_j are Fourier coefficients of periodic functions x
    and y, respectively, then::

      y_j = cosh(j*a*2*pi/period)/cosh(j*b*2*pi/period) * x_j

    Parameters
    ----------
    x : array_like
        The array to take the pseudo-derivative from.
    a,b : float
        Defines the parameters of the sinh/sinh pseudo-differential
        operator.
    period : float, optional
        The period of the sequence x. Default is ``2*pi``.

    Returns
    -------
    cc_diff : ndarray
        Pseudo-derivative of periodic sequence `x`.

    Notes
    -----
    ``cc_diff(cc_diff(x,a,b),b,a) == x``

    r   r   r   c                 <    t        || z        t        || z        z  S rO   )r   rG   s      r#   r$   zcc_diff.<locals>.kernel  s    !9T!A#Y&&r%   rQ   )r   r   r   r,   r-   r   r.   r/   r0   r   r1   r   rJ   s
             r#   r   r     s    : !*CCsxx!F+'#((1Qv../ 	/aCF6MaCF6MAAJJ!AwE}v;   1 	'006:!Awc1%KS;??r%   c                    t        |       }t        |      r2t        |j                  ||      dt        |j                  ||      z  z   S ||dz  t
        z  |z  }t        |       }|j                  ||f      }|it        |      dkD  r|r|j                          |r|fd}|fd}t        j                  ||dd      }	t        j                  ||dd      }
|	|
f|||f<   n|\  }	}
t        ||       }t        j                  ||	|
|	      S )
a  
    Shift periodic sequence x by a: y(u) = x(u+a).

    If x_j and y_j are Fourier coefficients of periodic functions x
    and y, respectively, then::

          y_j = exp(j*a*2*pi/period*sqrt(-1)) * x_f

    Parameters
    ----------
    x : array_like
        The array to take the pseudo-derivative from.
    a : float
        Defines the parameters of the sinh/sinh pseudo-differential
    period : float, optional
        The period of the sequences x and y. Default period is ``2*pi``.
    r   r   r   c                     t        || z        S rO   )r   r    rH   s     r#   kernel_realzshift.<locals>.kernel_real      qs8Or%   c                     t        || z        S rO   )r   rV   s     r#   kernel_imagzshift.<locals>.kernel_imag  rX   r%   r   r&   r   rQ   )r   r   r   r,   r-   r   r.   r/   r0   r   r1   r   
convolve_z)r2   rH   r3   r4   r5   r6   r7   rW   rZ   
omega_real
omega_imagr+   s               r#   r   r     s    $ !*CCSXXa'5!F+C(CCCaCF6MAAJJ!uE}v;    	  	55aaCDF
55aaCDF
":-!u %
:c1%Ks:j+68 8r%   )__doc____all__numpyr   r   r   r   r   r   r   r    r   scipy.fft._pocketfft.helperr   r4   r   r   r   r   r   r   r	   r
   r   r   rC   r%   r#   <module>rc      s  

 H G G  3 
 $v 66r  
 f =Q@  
 V !QH  
  :Qz  
 ! 3Ql  
 ! /Qd  
 ! .@b  
 ! 0@f  
 F ,8^ r%   