L i@>dZgdZddlZddlmZmZmZmZmZm Z m Z m Z ddl m Z ddlmZej ZddefdZdefd Zdefd Zefd Zefd Zdefd ZdefdZdefdZdefdZdefdZy)z1 Differential and pseudo-differential operators. ) difftilbertitilberthilbertihilbertcs_diffcc_diffsc_diffss_diffshiftN)piasarraysincossinhcoshtanh iscomplexobj)convolve) _datacopiedc^t|tjrt|dsi|_|j}t |}|dk(r|St |r4t|j|||dt|j|||zzS| dtz|z }nd}t|}|j|||f}|Jt|dkDr|r|j|r||fd}tj|||d }|||||f<t!||} tj|||dz| 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 ??c&|rt||z|SyNr )pow)kordercs a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/fftpack/_pseudo_diffs.pykernelzdiff..kernelIs1Q3u~%rd zero_nyquistswap_real_imag overwrite_x) isinstance threadinglocalhasattrrrrrrealimagr lengetpopitemrinit_convolution_kernelr) xr"period_cachetmpr#nomegar%r,s r$rrs?:&)//*v|, "F "" !*C z CCHHeVV4R HHeVV9-6-- -  bDK  AA JJ%{ #E } v;  !1 006E>?A#%{c1%K   Seai)4 66r&cBt|tjrt|dsi|_|j}t |}t |r4t|j|||dt|j|||zzS||dztz|z }t|}|j||f}|Gt|dkDr|r|j|r|fd}tj||d}||||f<t!||}tj||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_cacherrrc*|rdt||zz Sy)Nrr rr!hs r$r%ztilbert..kernels4!9}$r&rr(r*)r-r.r/r0r>rrrr1r2r r3r4r5rr6r r7rBr8r9r:r;r<r%r,s r$rrUsH&)//*v/#%F %% !*CCsxxFF3GCHHa889 9 EBJ  AA JJ1v E } v;    00Fa@!u c1%K   SaK PPr&cBt|tjrt|dsi|_|j}t |}t |r4t|j|||dt|j|||zzS||dztz|z }t|}|j||f}|Gt|dkDr|r|j|r|fd}tj||d}||||f<t!||}tj||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_cacherrrc&|rt||z Syrr@rAs r$r%zitilbert..kernelsQqS z!r&rrCr*)r-r.r/r0rFrrrr1r2r r3r4r5rr6rrDs r$rrs&)//*v/0$&F !&& !*CC!VV4(388Q778 8  aCF6M AA JJ!u E } v;   006A>!u c1%K   SaK PPr&c t|tjrt|dsi|_|j}t |}t |r0t|j|dt|j|zzSt|}|j|}|Ct|dkDr|r|j|rd}tj||d}|||<t||}tj||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_cacherrc|dkDry|dkryy)Nr rgg)r!s r$r%zhilbert..kernels1uQr&rrCr*)r-r.r/r0rIrrrr1r2r3r4r5rr6r)r7r9r:r;r<r%r,s r$rrsN&)//*v/#%F %% !*CCsxx(2&0I+III AA JJqME } v;    006A>q c1%K   SaK PPr&ct|tjrt|dsi|_|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/r0rMr)r7r9s r$rrs@&)//*v/0$&F !&& Av  r&c jt|tjrt|dsi|_|j}t |}t |r6t|j||||dt|j||||zzS||dztz|z }|dztz|z }t|}|j|||f}|It|dkDr|r|j|r||fd}tj||d}|||||f<t!||} tj||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_cacherrrcD|rt||z t||zz Syr)rrr!abs r$r%zcs_diff..kernelHs%QqS z$qs)++r&rrCr*)r-r.r/r0rOrrrr1r2r r3r4r5rr6r r7rRrSr8r9r:r;r<r%r,s r$rrs3<&)//*v/#%F %% !*CCsxxAvv6'#((Aq&&99: :  aCF6M aCF6M AA JJ!Aw E } v;  1 006A>!Awc1%K   SaK PPr&c jt|tjrt|dsi|_|j}t |}t |r6t|j||||dt|j||||zzS||dztz|z }|dztz|z }t|}|j|||f}|It|dkDr|r|j|r||fd}tj||d}|||||f<t!||} tj||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_cacherrrcB|rt||zt||zz Syr)rrrQs r$r%zsc_diff..kernels#AaCyac**r&rrCr*)r-r.r/r0rVrrr r1r2r r3r4r5rr6rrTs r$r r Rs34&)//*v/#%F %% !*CCsxxAvv6GCHHaFF;;< <  aCF6M aCF6M AA JJ!Aw E } v;  1 006A>!Awc1%K   SaK PPr&c dt|tjrt|dsi|_|j}t |}t |r6t|j||||dt|j||||zzS||dztz|z }|dztz|z }t|}|j|||f}|Gt|dkDr|r|j|r||fd}tj||}|||||f<t!||} tj||| 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_cacherrrc\|rt||zt||zz St||z SN)rfloatrQs r$r%zss_diff..kernels.AaCyac**8A: r&r,)r-r.r/r0rYrrr r1r2r r3r4r5rr6rrTs r$r r s/2&)//*v/#%F %% !*CCsxxAvv6'#((Aq&&99: :  aCF6M aCF6M AA JJ!Aw E } v;  1 006:!Awc1%K   S; ??r&c dt|tjrt|dsi|_|j}t |}t |r6t|j||||dt|j||||zzS||dztz|z }|dztz|z }t|}|j|||f}|Gt|dkDr|r|j|r||fd}tj||}|||||f<t!||} tj||| 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_cacherrrc<t||zt||zz Sr[)rrQs r$r%zcc_diff..kernels!9T!A#Y& &r&r])r-r.r/r0r_rrrr1r2r r3r4r5rr6rrTs r$rrs-:&)//*v/#%F %% !*CCsxxAvv6GCHHaFF;;< <  aCF6M aCF6M AA JJ!Aw E } v;  1 '006:!Awc1%K   S; ??r&ct|tjrt|dsi|_|j}t |}t |r4t|j|||dt|j|||zzS||dztz|z }t|}|j||f}|it|dkDr|r|j|r|fd}|fd}tj||dd} tj||d d} | | f|||f<n|\} } t!||} tj"|| | | 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_cacherrrct||zSr[)rr!rRs r$ kernel_realzshift..kernel_realqs8Or&ct||zSr[)rrds r$ kernel_imagzshift..kernel_imagrfr&r r'rr])r-r.r/r0rbrrr r1r2r r3r4r5rr6r convolve_z) r7rRr8r9r:r;r<rerh omega_real omega_imagr,s r$r r sX$&)//*v}-!#F ## !*CCSXXq&&1B HHa:)5)) )  aCF6M AA JJ!u E } v;    55a aCDF 55a aCDF ":-!u % :c1%K   s:j+6 88r&)__doc____all__r.numpyr rrrrrrrrscipy.fft._pocketfft.helperrr/r9rrrrrrr r rr rKr&r$rqs   GGG3  $v<6~fBQJV&QR?QD$!8Qv!4Qn!3@l!5@pF28r&