L i:1ddlZddlmZddlmZddlZddlmZ ddl m Z m Z ddl mZmZddlmZmZddlmZej*j,Zdd ZGd d Zd Zed dGddZed ddZy)N)product)raises)array_api_extra)xp_assert_closearray_namespace)upfirdnfirwin) _output_len_upfirdn_modes) _pad_testc<tj|}tj|}tjt||z|j}||dd|<tj ||dd|dt t|t|||}|S)zpNaive upfirdn processing in Python. Note: arg order (x, h) differs to facilitate apply_along_axis use. N)npasarrayzeroslendtypeconvolver )xhupdownouts e/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/signal/tests/test_upfirdn.py upfirdn_naiver5s 1 A 1 A ((3q6B; (CC"I ++a ff %&L{3q63q62t'L MC Jc$eZdZdZdZdZddZy) UpFIRDnCasezTest _UpFIRDn objectc||_||_tj||_||_tj jd|_y)N) rrr atleast_1drx_dtyperandom RandomStaterng)selfrrrr!s r__init__zUpFIRDnCase.__init__Ds= q! 99((,rc@|jtjd|j|jtjd|j|jj dj |j}|jtjtjfvr!|d|jj dzz }|j||jtjdj |jd}|jj |j |j}|jtjtjfvr|d|jj |zz }tt|D]}|j|||ddddddddfj}tt|D]}|j||y)N ?)axisr+r,) scrubronesr!r$randnastype complex64 complex128arangerangerT)r%rsizer/s r__call__zUpFIRDnCase.__call__Ks 2771dll+, 2772t||,- HHNN2  % %dll 3 <z$UpFIRDnCase.scrub..ks1QqBLL 1c3BK|]}|tjk(ywr=)rfloat32r>s rrAz$UpFIRDnCase.scrub..os1Qbjj1rB)rapply_along_axisrrrrr rshaperrallr4rDr5float64rr3)r%rr/yrwant_lenydtypess rr0zUpFIRDnCase.scrubbs  a!%$))=s466{AGGDM477DIINxx~))) DFFAtww  =wwt}(((ww"(("""&&,,( 1&1 177bll* ** \\V # f(<77bll* ** 1&1 177bjj( (( ]]f $ (>77bmm+ ++77bjj( (( !''*A.rN))__name__ __module__ __qualname____doc__r&r:r0rrrrBs-%./rrint64rDr4rHr5TzCython implementation)cpu_onlyreasonc VeZdZedddZej jdgdej jdgddZd Z ej jd d d d d gd fd dddgdfd dddgdfdd dd gdfdddd gdfgdZ ej jdgdej jdgddZ eddej jde ej jddej jd gd!d"Z eddej jde ej jd#e ej jd$eed%d%d&Zd'Zej jd(ed)Zej jd*ed+ggd,egd-d.Zy/)0 TestUpfirdnTzenough to only test on numpy)np_onlyrVctttdgdgddtttgdgddtttdggdgddy)Nr(r) assert_raises ValueErrorr)r%xps rtest_valid_inputzTestUpfirdn.test_valid_input~sDj'A3Q:j'2sAq9j'QC51#q!atolrtol)rr"r#getattrr2r3r4r5rr rrrFr) r%rrJrr] random_stater9np_dtyperrylrKs rtest_vs_convolvezTestUpfirdn.test_vs_convolvesyy,,R0 2u%   t $ + +H 5  bmm4 4 l((.. .AE" JJqJ & JJvb"t)I> ? ZZ aAt4 5 AqQT *ww8+%%%xx{aggaj(((ADt4rrEr!r)rcr*zup, down)r(r()r+r+)r,r+)r+r,c*t||||yr=)r)r%r!rrrr]s rtest_vs_naive_deltazTestUpfirdn.test_vs_naive_deltas * Ba)+rh_dtypez p_max, q_max)r)dcH|j||||}|D] }| yr=)_random_factors)r%r!rp_maxq_maxr]teststests r test_vs_naivezTestUpfirdn.test_vs_naives. $$UE7GD D F rc d}d}tjjd}g}t|D]} ||kDr|nd} ||kDr|nd} |j || z} |j || z} |j |dz}tj |j |}|j |}|tur|d|j |zz }|jt| | |||S)Nr,rr(r*) rr"r#r7randintr r3complexappendr)r%rrrr!n_rep longest_hr~r_p_addq_addpqr_rs rrzTestUpfirdn._random_factorss yy,,R0 u 8A"U]EE"U]EE$$U+e3A$$U+e3A!((3a7E l2259:A!A'!R,..u555 LLQ1g6 7 8  rmodecRtjgdtj}d\}}t||||}|j|}|j|}|dk(r|jgd}n|dk(r|jgd}n|d k(r|jgd }n|d k(r|d |d z |jd dz z }|d |j | d d|j|zz} |d |j d|dz|j|zz} t | j} | | || f}n>tjtj|||f|}|j|}|j||j}t||y)z@Test vs. manually computed results for modes not in numpy's pad.)r(r+r,r(rl)roronprenpostr antisymmetric)g@r(rMrMr(r+r,r(rMrrrMr(r+ antireflect)rcr+r,r(rMrr(r+r,r(rMrr(r+r,r(smooth)grrrMrr(r+r,r(rMriiilinerMrr(rN) rrrHr rFr6rconcatrhr) r%rr]rrrrK y_expected lin_slopeleftrightrs rtest_extensionszTestUpfirdn.test_extensionss JJ|2:: 6 e ad%d ; JJqM JJqM ? "JLJ ] "DFJ X NPJ V^21!''!*q.9IQ4"))TE1arzz)BYNNDbEBIIa"**IE QQE$T*11Fq% 01J 1 e}4HJJ/JZZ "**Z= :&rzsize, h_len, mode, dtype)r`r-)rDrHr4r5ctt|}t||}tjjd}|j |j |} |dvr| d|j |zz } tj dd|z| jj} |j| |} |j| } t| | dd|} |dz } |dvr#ttj| | | |} n+tjtj| | | } |j| } t| | ddd }|| | }|j|jd zx}}t| ||| y) Nr-)r4r5r*r(rl)rrr)rrrrrrrdgY@rz)r}rr"r#r2r3r6realrrrr rhfinfoepsr)r%r9h_lenrrr]dtype_npdtype_xpr~rrrKnpadxpadypadrr{r|s r test_modeszTestUpfirdn.test_modess[2u%2u%yy,,Q/   t $ + +H 5 / / l((.. .A IIaU!&&,, 7 JJqJ ) JJqM AqQQT 2qy E ERZZ]TMD66"**Q-D9Dzz$q$11:>$u% hhx(,,s22t:Dt [[Y7 [[S(+ [[Z)IJ,K,8?,d+=> [[Y7 [[Y7 [[^!')Y"?@BB88?  0 [[V^4'5'< [[" C   =  ==rrXc>d}d}d}d}t||||}|dk(sJy)Niii@ii6S)r )r]r_in_lenrrout_lens rtest_output_len_long_inputr6s8 E F B D%T2G h  rr)numpyr itertoolsrrrr[ scipy._librrescipy._lib._array_apirr scipy.signalrr scipy.signal._upfirdnr r scipy.signal._upfirdn_applyr rrrrrrXrrRrrrsF* -)=1;;// 3/3/lL4(?@w=w=Aw=t4(?@ A r