
    ^Mh@>                         d Z g dZddl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  ej                    ZddefdZdefd	Zdefd
ZefdZefdZdefdZdefdZdefdZdefdZdefdZdS )z1
Differential and pseudo-differential operators.
)
difftilbertitilberthilbertihilbertcs_diffcc_diffsc_diffss_diffshift    N)piasarraysincossinhcoshtanhiscomplexobj   )convolve)_datacopiedc                    t          |t          j                  rt          |d          si |_        |j        }t          |           }|dk    r|S t          |          r2t          |j        |||          dt          |j	        |||          z  z   S |dt          z  |z  }nd}t          |           }|                    |||f          }|Qt          |          dk    r|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.

    
diff_cacher                 ?N         ?   c                 0    | rt          || z  |          S dS Nr   )pow)kordercs      [/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/scipy/fftpack/_pseudo_diffs.pykernelzdiff.<locals>.kernelI   s!     &1Q3u~~%1    r   dzero_nyquistswap_real_imagoverwrite_x)
isinstance	threadinglocalhasattrr   r   r   r   realimagr   lengetpopitemr   init_convolution_kernelr   )
xr"   period_cachetmpr#   nomegar%   r,   s
             r$   r   r      s   : &)/** #v|,, 	# "F"
!**Czz
C -CHeVV44RHeVV9- 9- 6- - 	-bDKAAJJ%{##E}v;; !     ! !1 	 	 	 	 06E>?A A A#%{c1%%KSeai)46 6 6 6r&   c                 r   t          |t          j                  rt          |d          si |_        |j        }t          |           }t          |          r2t          |j        |||          dt          |j	        |||          z  z   S ||dz  t          z  |z  }t          |           }|                    ||f          }|Nt          |          dk    r|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.

    tilbert_cacher   Nr   r   c                 4    | rdt          || z            z  S dS )Nr   r   r   r!   hs     r$   r%   ztilbert.<locals>.kernel   s#     %4!99}$1r&   r   r(   r*   )r-   r.   r/   r0   r>   r   r   r   r1   r2   r   r3   r4   r5   r   r6   r   	r7   rB   r8   r9   r:   r;   r<   r%   r,   s	            r$   r   r   U   se   H &)/** &v// 	&#%F %
!**CC 9sxFF33GCHa8889 	9 EBJAAJJ1vE}v;; !     !  	 	 	 	 0Fa@@@!uc1%%KSaKPPPPr&   c                 r   t          |t          j                  rt          |d          si |_        |j        }t          |           }t          |          r2t          |j        |||          dt          |j	        |||          z  z   S ||dz  t          z  |z  }t          |           }|                    ||f          }|Nt          |          dk    r|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`.

    itilbert_cacher   Nr   r   c                 0    | rt          || z             S dS r   r@   rA   s     r$   r%   zitilbert.<locals>.kernel   s!     "QqS		z!1r&   r   rC   r*   )r-   r.   r/   r0   rF   r   r   r   r1   r2   r   r3   r4   r5   r   r6   r   rD   s	            r$   r   r      sb    &)/** 'v/00 	'$&F!&
!**CC 8!VV44(38Q7778 	8aCF6MAAJJ!uE}v;; !     !  	 	 	 	 06A>>>!uc1%%KSaKPPPPr&   c                 :   t          |t          j                  rt          |d          si |_        |j        }t          |           }t          |          r.t          |j        |          dt          |j	        |          z  z   S t          |           }|                    |          }|Jt          |          dk    r|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.

    hilbert_cacher   Nr   c                 &    | dk    rdS | dk     rdS dS )Nr   r   g      g         )r!   s    r$   r%   zhilbert.<locals>.kernel   s#    1uusQt3r&   r   rC   r*   )r-   r.   r/   r0   rI   r   r   r   r1   r2   r3   r4   r5   r   r6   r   )r7   r9   r:   r;   r<   r%   r,   s          r$   r   r      s+   N &)/** &v// 	&#%F %
!**CC Jsx((2&0I0I+IIIAAJJqMME}v;; !     !	 	 	 06A>>>q	c1%%KSaKPPPPr&   c                     t          |t          j                  rt          |d          si |_        |j        }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

    ihilbert_cache)r-   r.   r/   r0   rM   r   )r7   r9   s     r$   r   r     sN     &)/** 'v/00 	'$&F!&Avr&   c           	         t          |t          j                  rt          |d          si |_        |j        }t          |           }t          |          r4t          |j        ||||          dt          |j	        ||||          z  z   S | |dz  t          z  |z  }|dz  t          z  |z  }t          |           }|                    |||f          }|Pt          |          dk    r|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.

    cs_diff_cacher   Nr   r   c                 V    | r&t          || z             t          || z            z  S dS r   )r   r   r!   abs      r$   r%   zcs_diff.<locals>.kernelH  s0     ,QqS		z$qs))++1r&   r   rC   r*   )r-   r.   r/   r0   rO   r   r   r   r1   r2   r   r3   r4   r5   r   r6   r   
r7   rR   rS   r8   r9   r:   r;   r<   r%   r,   s
             r$   r   r     s|   < &)/** &v// 	&#%F %
!**CC :sxAvv66'#(Aq&&999: 	:aCF6MaCF6MAAJJ!AwE}v;; !     ! 1 	 	 	 	 06A>>>!Awc1%%KSaKPPPPr&   c           	         t          |t          j                  rt          |d          si |_        |j        }t          |           }t          |          r4t          |j        ||||          dt          |j	        ||||          z  z   S | |dz  t          z  |z  }|dz  t          z  |z  }t          |           }|                    |||f          }|Pt          |          dk    r|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.

    sc_diff_cacher   Nr   r   c                 T    | r%t          || z            t          || z            z  S dS r   )r   r   rQ   s      r$   r%   zsc_diff.<locals>.kernel  s.     +AaCyyac**1r&   r   rC   r*   )r-   r.   r/   r0   rV   r   r   r	   r1   r2   r   r3   r4   r5   r   r6   r   rT   s
             r$   r	   r	   R  s|   4 &)/** &v// 	&#%F %
!**CC <sxAvv66GCHaFF;;;< 	<aCF6MaCF6MAAJJ!AwE}v;; !     ! 1 	 	 	 	 06A>>>!Awc1%%KSaKPPPPr&   c           	         t          |t          j                  rt          |d          si |_        |j        }t          |           }t          |          r4t          |j        ||||          dt          |j	        ||||          z  z   S | |dz  t          z  |z  }|dz  t          z  |z  }t          |           }|                    |||f          }|Nt          |          dk    r|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``

    ss_diff_cacher   Nr   r   c                 t    | r%t          || z            t          || z            z  S t          |          |z  S N)r   floatrQ   s      r$   r%   zss_diff.<locals>.kernel  s9     +AaCyyac**88A:r&   r,   )r-   r.   r/   r0   rY   r   r   r
   r1   r2   r   r3   r4   r5   r   r6   r   rT   s
             r$   r
   r
     su   2 &)/** &v// 	&#%F %
!**CC :sxAvv66'#(Aq&&999: 	:aCF6MaCF6MAAJJ!AwE}v;; !     ! 1 	 	 	 	 06::!Awc1%%KS;????r&   c           	         t          |t          j                  rt          |d          si |_        |j        }t          |           }t          |          r4t          |j        ||||          dt          |j	        ||||          z  z   S | |dz  t          z  |z  }|dz  t          z  |z  }t          |           }|                    |||f          }|Nt          |          dk    r|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``

    cc_diff_cacher   Nr   r   c                 L    t          || z            t          || z            z  S r[   )r   rQ   s      r$   r%   zcc_diff.<locals>.kernel  s!    !99T!A#YY&&r&   r]   )r-   r.   r/   r0   r_   r   r   r   r1   r2   r   r3   r4   r5   r   r6   r   rT   s
             r$   r   r     ss   : &)/** &v// 	&#%F %
!**CC <sxAvv66GCHaFF;;;< 	<aCF6MaCF6MAAJJ!AwE}v;; !     ! 1 	' 	' 	' 	'06::!Awc1%%KS;????r&   c                    t          |t          j                  rt          |d          si |_        |j        }t          |           }t          |          r2t          |j        |||          dt          |j	        |||          z  z   S ||dz  t          z  |z  }t          |           }|                    ||f          }|ot          |          dk    r|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``.
    shift_cacher   Nr   r   c                 &    t          || z            S r[   )r   r!   rR   s     r$   kernel_realzshift.<locals>.kernel_real      qs88Or&   c                 &    t          || z            S r[   )r   rd   s     r$   kernel_imagzshift.<locals>.kernel_imag  rf   r&   r   r'   r   r]   )r-   r.   r/   r0   rb   r   r   r   r1   r2   r   r3   r4   r5   r   r6   r   
convolve_z)r7   rR   r8   r9   r:   r;   r<   re   rh   
omega_real
omega_imagr,   s               r$   r   r     s   $ &)/** $v}-- 	$!#F#
!**CC )SXq&&11BHa:) :) 5) ) 	)aCF6MAAJJ!uE}v;; !     !  	 	 	 	  	 	 	 	5aaCDF F F
5aaCDF F F
":-!u %
:c1%%Ks:j+68 8 8 8r&   )__doc____all__r.   numpyr   r   r   r   r   r   r   r    r   scipy.fft._pocketfft.helperr   r/   r9   r   r   r   r   r   r   r	   r
   r   r   rK   r&   r$   <module>rq      s   
  
     G G G G G G G G G G G G G G G G G G G G       3 3 3 3 3 3 
		 $v <6 <6 <6 <6~ f BQ BQ BQ BQJ V &Q &Q &Q &QR  ?Q ?Q ?Q ?QD     $ ! 8Q 8Q 8Q 8Qv ! 4Q 4Q 4Q 4Qn ! 3@ 3@ 3@ 3@l ! 5@ 5@ 5@ 5@p F 28 28 28 28 28 28r&   