
    >qj_B                     &   d dl Zd dlZd dlmZ d dlmZmZmZm	Z	m
Z
mZ d dlmc mZ d dlmZmZ d ZddZd Zd Zd	 Z G d
 d      Z G d d      Z G d d      Z G d d      Z e
e       G d d             Z e
e       G d d             Zy)    N)raises)assert_almost_equalxp_assert_equalxp_assert_close_xp_copy_to_numpymake_xp_test_casexp_default_dtype)squaresawtoothc                 "    |||z
  | z  |z  z   }|S N tf0f1t1fs        `/opt/rentech/trading_bot/.venv/lib/python3.12/site-packages/scipy/signal/tests/test_waveforms.pychirp_linearr      s    
b2g]RAH    c                 d    |r|||z
  | dz  z  |dz  z  z   }|S |||z
  || z
  dz  z  |dz  z  z
  }|S )N   r   )r   r   r   r   vertex_zeror   s         r   chirp_quadraticr      sW    "r'QT!BE)) H "r'b1fq[(2q500Hr   c                 "    |||z  | |z  z  z  }|S r   r   r   s        r   chirp_geometricr      s    
beqt_AHr   c                 4    ||z  |z  ||z
  | z  ||z  z   z  }|S r   r   r   s        r   chirp_hyperbolicr   "   s*    
2bR"WaK"R%'(AHr   c                     | d   | d   z
  }t        j                  |      dt         j                  z  z  |z  }d| dd | dd z   z  }||fS )zR
    Compute theta'(t)/(2*pi), where theta'(t) is the derivative of theta(t).
       r   r         ?N)npdiffpi)r   thetadtr   tfs        r   compute_frequencyr*   '   sW     
1!B
"%% 2%A	aeafn	Bq5Lr   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)	TestChirpc                 P    t        j                  ddddd      }t        |d       y )Nr         ?       @linearr   r   r   r   method	waveformschirpr   selfws     r   test_linear_at_zerozTestChirp.test_linear_at_zero5   s"    OOaCCCIAs#r   c                    d}d}d}d}t        j                  d|d      }t        j                  |||||      }t	        ||      \  }}t        j
                  t        j                  |t        ||||      z
              }	|	dk  sJ y )Nr0   r.   r/   r   d   ư>r$   linspacer4   _chirp_phaser*   maxabsr   
r7   r2   r   r   r   r   phaser)   r   abserrs
             r   test_linear_freq_01zTestChirp.test_linear_freq_019   s    KK2s#&&q"b"f=!!U+Aq<BB#??@A}}r   c                    d}d}d}d}t        j                  d|d      }t        j                  |||||      }t	        ||      \  }}t        j
                  t        j                  |t        ||||      z
              }	|	dk  sJ y )Nr0         i@      Y@      $@r   r;   r<   r=   rB   s
             r   test_linear_freq_02zTestChirp.test_linear_freq_02D   s    KK2s#&&q"b"f=!!U+Aq<BB#??@A}}r   c                 @   d}d}d}d}t        j                  d|d      }t        j                  |||||d      }t        j                  |||||d      }t        j                  |      }t        j                  |      }	|t        j
                  |	      z
  }
|
d	k  sJ y )
Nr0   r.   r/   r   r;   F)complexTr<   )r$   r>   r4   r5   varreal)r7   r2   r   r   r   r   w_real	w_complexw_pwr_rw_pwr_cerrs              r   test_linear_complex_powerz#TestChirp.test_linear_complex_powerO   s    KK2s#BBFOOAr2r64H	&&.&&# ((Tzzr   c                 R    t        j                  dddddd      }t        |d       y )Nr         $r.   r0   Tr   r   r   r   r2   rL         ?        r4   r5   r   r6   s     r   test_linear_complex_at_zeroz%TestChirp.test_linear_complex_at_zero`   s'    OOaEcc($(*8$r   c                 P    t        j                  ddddd      }t        |d       y )Nr   r.   r/   	quadraticr1   r3   r6   s     r   test_quadratic_at_zeroz TestChirp.test_quadratic_at_zeroe   s"    OOaCCCLAs#r   c                 R    t        j                  dddddd      }t        |d       y )Nr   r.   r/   r\   F)r   r   r   r   r2   r   r3   r6   s     r   test_quadratic_at_zero2z!TestChirp.test_quadratic_at_zero2i   s'    OOaCCC(-/As#r   c                 R    t        j                  dddddd      }t        |d       y )	Nr         r/   r.   r\   TrW   rX   rY   r6   s     r   test_quadratic_complex_at_zeroz(TestChirp.test_quadratic_complex_at_zeron   s'    OOaDSS$(*6"r   c                    d}d}d}d}t        j                  d|d      }t        j                  |||||      }t	        ||      \  }}t        j
                  t        j                  |t        ||||      z
              }	|	dk  sJ y )Nr\   r.   r/   r     r<   r$   r>   r4   r?   r*   r@   rA   r   rB   s
             r   test_quadratic_freq_01z TestChirp.test_quadratic_freq_01s   s    KK2t$&&q"b"f=!!U+Aq?2r2r#BBCD}}r   c                    d}d}d}d}t        j                  d|d      }t        j                  |||||      }t	        ||      \  }}t        j
                  t        j                  |t        ||||      z
              }	|	dk  sJ y )Nr\         4@rI   r   rd   r<   re   rB   s
             r   test_quadratic_freq_02z TestChirp.test_quadratic_freq_02~   s    KK2t$&&q"b"f=!!U+Aq?2r2r#BBCD}}r   c                 P    t        j                  ddddd      }t        |d       y )Nr   r.   r/   logarithmicr1   r3   r6   s     r   test_logarithmic_at_zeroz"TestChirp.test_logarithmic_at_zero   s"    OOaCCCNAs#r   c                    d}d}d}d}t        j                  d|d      }t        j                  |||||      }t	        ||      \  }}t        j
                  t        j                  |t        ||||      z
              }	|	dk  sJ y )Nrk   r.   r/   r   '  r<   r$   r>   r4   r?   r*   r@   rA   r   rB   s
             r   test_logarithmic_freq_01z"TestChirp.test_logarithmic_freq_01   s    KK2u%&&q"b"f=!!U+Aq?2r2r#BBCD}}r   c                    d}d}d}d}t        j                  d|d      }t        j                  |||||      }t	        ||      \  }}t        j
                  t        j                  |t        ||||      z
              }	|	dk  sJ y )Nrk   rG   rH   rI   r   rn   r<   ro   rB   s
             r   test_logarithmic_freq_02z"TestChirp.test_logarithmic_freq_02       KK2u%&&q"b"f=!!U+Aq?2r2r#BBCD}}r   c                    d}d}d}d}t        j                  d|d      }t        j                  |||||      }t	        ||      \  }}t        j
                  t        j                  |t        ||||      z
              }	|	dk  sJ y )Nrk   rH   rI   r   rn   r<   ro   rB   s
             r   test_logarithmic_freq_03z"TestChirp.test_logarithmic_freq_03   rs   r   c                 P    t        j                  ddddd      }t        |d       y )Nr   rI   r.   
hyperbolicr1   r3   r6   s     r   test_hyperbolic_at_zeroz!TestChirp.test_hyperbolic_at_zero   s"    OOaDSSNAs#r   c                     d}d}t        j                  d|d      }ddgddgddgddgg}|D ]I  \  }}t        j                  |||||      }t	        ||      \  }}	t        ||||      }
t        |	|
d	       K y )
Nrw   r.   r   rn   rI   rV   ra   gHz>)atol)r$   r>   r4   r?   r*   r   r   )r7   r2   r   r   casesr   r   rC   r)   r   expecteds              r   test_hyperbolic_freq_01z!TestChirp.test_hyperbolic_freq_01   s    KK2u%t   	4FB**1b"b&AE%a/EB'BB7HAxd3		4r   c           	          d}d}t        j                  d|d      }t        t        t        j
                  |d|d|       t        t        t        j
                  |d|d|       y )Nrw   r.   r      r!   r$   r>   assert_raises
ValueErrorr4   r5   )r7   r2   r   r   s       r   test_hyperbolic_zero_freqz#TestChirp.test_hyperbolic_zero_freq   sN    KK2q!j)//1aQGj)//1aQGr   c           	          d}d}d}d}t        j                  d|d      }t        t        t        j
                  |||||       y )NfoorI   rh   r.   r   
   r   )r7   r2   r   r   r   r   s         r   test_unknown_methodzTestChirp.test_unknown_method   s@    KK2r"j)//1b"b&Ir   c                     d}d}t        j                  ddd      }d}t        j                  ||||      }d}t        j                  ||||      }d}t	        |||	       y )
NrI   rh   r#   r!            @   z'Integer input 't1=3' gives wrong resulterr_msgr$   r>   r4   r5   r   )r7   r   r   r   r   float_result
int_resultr   s           r   test_integer_t1zTestChirp.test_integer_t1   sa    KKAr" q"b"5__QB3
;
L'Br   c                     d}d}t        j                  ddd      }d}t        j                  ||||      }d}t        j                  ||||      }d}t	        |||	       y )
Nrh   r   r#   r!   r   rI   r   z(Integer input 'f0=10' gives wrong resultr   r   )r7   r   r   r   r   r   r   r   s           r   test_integer_f0zTestChirp.test_integer_f0   a    KKAr" q"b"5__QB3
<
L'Br   c                     d}d}t        j                  ddd      }d}t        j                  ||||      }d}t        j                  ||||      }d}t	        |||	       y )
NrI   r   r#   r!   r   rh      z(Integer input 'f1=20' gives wrong resultr   r   )r7   r   r   r   r   r   r   r   s           r   test_integer_f1zTestChirp.test_integer_f1   r   r   c                     d}d}d}t        j                  ddd      }t        j                  |t	        |      t	        |      t	        |            }t        j                  ||||      }d}t        |||       y )	Nr   r   r   r#   r!   r   z5Integer input 'f0=10, t1=3, f1=20' gives wrong resultr   )r$   r>   r4   r5   floatr   )r7   r   r   r   r   r   r   r   s           r   test_integer_allzTestChirp.test_integer_all   sh    KKAr" q%)U2Yb	J__QB3
I
L'Br   N)__name__
__module____qualname__r9   rE   rJ   rT   rZ   r]   r_   rb   rf   ri   rl   rp   rr   ru   rx   r}   r   r   r   r   r   r   r   r   r   r,   r,   3   sv    $		"%
$$
#
		$			$4HJ	C	C	CCr   r,   c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	TestSweepPolyc                    t        j                  g d      }t        j                  ddd      }t        j                  ||      }t        ||      \  }} ||      }t        j                  t        j                  ||z
              }|dk  sJ y )N)r.           r.   r   r   rn   r<   r$   poly1dr>   r4   _sweep_poly_phaser*   r@   rA   r7   pr   rC   r)   r   r|   rD   s           r   test_sweep_poly_quad1z#TestSweepPoly.test_sweep_poly_quad1   st    IIo&KK3&++Aq1!!U+AR5q8|,-}}r   c                    t        j                  d      }t        j                  ddd      }t        j                  ||      }t        ||      \  }} ||      }t        j                  t        j                  ||z
              }|dk  sJ y )Nr/   r   r   rn   r<   r   r   s           r   test_sweep_poly_constz#TestSweepPoly.test_sweep_poly_const  ss    IIcNKK3&++Aq1!!U+AR5q8|,-}}r   c                    t        j                  ddg      }t        j                  ddd      }t        j                  ||      }t        ||      \  }} ||      }t        j                  t        j                  ||z
              }|dk  sJ y )Nra   rI   r   r   rn   r<   r   r   s           r   test_sweep_poly_linearz$TestSweepPoly.test_sweep_poly_linear  sx    IItTl#KK3&++Aq1!!U+AR5q8|,-}}r   c                    t        j                  g d      }t        j                  ddd      }t        j                  ||      }t        ||      \  }} ||      }t        j                  t        j                  ||z
              }|dk  sJ y )N)r.   r          r   r   rn   r<   r   r   s           r   test_sweep_poly_quad2z#TestSweepPoly.test_sweep_poly_quad2  su    II&'KK3&++Aq1!!U+AR5q8|,-}}r   c                    t        j                  g d      }t        j                  ddd      }t        j                  ||      }t        ||      \  }} ||      }t        j                  t        j                  ||z
              }|dk  sJ y )Nr/   r.   r   r   r   r/   rn   r<   r   r   s           r   test_sweep_poly_cubicz#TestSweepPoly.test_sweep_poly_cubic#  su    II+,KK3&++Aq1!!U+AR5q8|,-}}r   c                 D   t        j                  g d      }t        j                  ddd      }t        j                  ||      }t        ||      \  }} t        j                  |      |      }t        j                  t        j                  ||z
              }|dk  sJ y)z1Use an array of coefficients instead of a poly1d.r   r   r/   rn   r<   N)	r$   arrayr>   r4   r   r*   r   r@   rA   r   s           r   test_sweep_poly_cubic2z$TestSweepPoly.test_sweep_poly_cubic2,  s    HH*+KK3&++Aq1!!U+A299Q<#q8|,-}}r   c                    g d}t        j                  ddd      }t        j                  ||      }t	        ||      \  }} t        j
                  |      |      }t        j                  t        j                  ||z
              }|dk  sJ y)z/Use a list of coefficients instead of a poly1d.r   r   r/   rn   r<   N)r$   r>   r4   r   r*   r   r@   rA   r   s           r   test_sweep_poly_cubic3z$TestSweepPoly.test_sweep_poly_cubic36  sv    !KK3&++Aq1!!U+A299Q<#q8|,-}}r   N)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s%    r   r   c                   $    e Zd Zd Zd Zd Zd Zy)TestGaussPulsec                     t        j                  dd      }t        j                  dd      }d}t        |||       y )Ncutoffg     @@)fc  z*Integer input 'fc=1000' gives wrong resultr   r4   
gausspulser   r7   r   r   r   s       r   test_integer_fczTestGaussPulse.test_integer_fcC  s7     ++H@))(t<
>
L'Br   c                     t        j                  dd      }t        j                  dd      }d}t        |||       y )Nr   r.   )bwr!   z'Integer input 'bw=1' gives wrong resultr   r   r   s       r   test_integer_bwzTestGaussPulse.test_integer_bwI  s7     ++H=))(q9
;
L'Br   c                     t        j                  dd      }t        j                  dd      }d}t        |||       y )Nr   g      )bwriz)Integer input 'bwr=-6' gives wrong resultr   r   r   s       r   test_integer_bwrzTestGaussPulse.test_integer_bwrO  s7     ++H$?))(;
=
L'Br   c                     t        j                  dd      }t        j                  dd      }d}t        |||       y )Nr   g      N)tpriz*Integer input 'tpr=-60' gives wrong resultr   r   r   s       r   test_integer_tprzTestGaussPulse.test_integer_tprU  s7     ++H%@))(<
>
L'Br   N)r   r   r   r   r   r   r   r   r   r   r   r   A  s    CCCCr   r   c                   $    e Zd Zd Zd Zd Zd Zy)TestUnitImpulsec           	          t        t        j                  d      t        j                  g d             t        t        j                  d      t        j                  g dg dg dg             y )N   )r.   r   r   r   r   r   r   r   r   )r.   r   r   r   r   r   r   r4   unit_impulser$   asarrayr7   s    r   test_no_indexzTestUnitImpulse.test_no_index^  sM    	..q1

#:;	=	..v6

KI#FG	Ir   c           
      h   t        t        j                  dd      t        j                  g d             t        t        j                  dd      t        j                  g dg dg dg             t        j                  d	d
      }t        |t        j                  g dg dg dg dg             y )Nr   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   r7   imps     r   
test_indexzTestUnitImpulse.test_indexd  s    	..r15

#CD	F	..vv>

KI#FG	I $$VQ/RZZ)7)7)7)9 : 	;r   c           	          t        t        j                  dd      t        j                  g dg dg dg             t        t        j                  dd      t        j                  g d             y )Nr   midr   r   r   	   )	r   r   r   r   r!   r   r   r   r   r   r   s    r   test_midzTestUnitImpulse.test_midq  sR    	..vu=

KI#FG	I	..q%8

#@A	Cr   c                    t        j                  d      }t        j                  |j                  t        j
                        sJ t        j                  ddt              }t        j                  |j                  t        j                        sJ t        j                  ddt              }t        j                  |j                  t        j                        sJ y )Nr   r   r   dtype)r   r   )r   r!   )
r4   r   r$   
issubdtyper   floatingintintegerrL   complexfloatingr   s     r   
test_dtypezTestUnitImpulse.test_dtypew  s    $$Q'}}SYY444$$Q5}}SYY

333$$VV7C}}SYY(:(:;;;r   N)r   r   r   r   r   r   r   r   r   r   r   r   \  s    I;C<r   r   c                   .   e Zd Zej                  j                  dd      ej                  j                  dddg      ej                  j                  dddg      d                      Zd	 Zd
 Z	d Z
ej                  j                  dd      d        Zy)TestSawtoothWaveformcupycupy/cupy/issues/9541reasont_dtypefloat32float64width_dtypec                     t        ||      }t        ||      }t        |j                  d|      |j                  d|            }|j                  |j	                  ||      k(  sJ y )Nr!   r   width)getattrr   r   r   result_type)r7   r   r   xpwaveforms        r   r   zTestSawtoothWaveform.test_dtype  sd     "g&b+.JJqJ(

1K
0P
 ~~!EEEEr   c                     |j                  dd|j                  z  d|j                        }t        |d      }t        |d|j                  z  z   d      }t	        ||       y )Nr   r   r;   r   皙?r   )r>   r&   r   r   r   r7   r   r   y1y2s        r   test_periodicz"TestSawtoothWaveform.test_periodic  sR    KK1RUU7CrzzK:as#a!BEE'k-Br   c                    |j                  t        |            j                  }|j                  d|j                  d|j                  z  d|z  z
  d|j                  z  g      }t        |      }t        ||j                  g d             y )Nr   r   r   )ra   r   r.   ra   )finfor	   epsr   r&   r   r   )r7   r   r  r   ys        r   test_known_valuesz&TestSawtoothWaveform.test_known_values  sm    hh'+,00JJ255!BEE'BsF"2AbeeG<=QK2::&89:r   c                     |j                  dd|j                  z  d      }t        |d      }|j                  |j	                  |            sJ y )Nr   r   r   g      ?r   )r>   r&   r   allisnanr7   r   r   r  s       r   test_invalid_width_nanz+TestSawtoothWaveform.test_invalid_width_nan  sB    KK1RUU7B'Qc"vvbhhqk"""r   zcupy/cupy/issues/9568c                     |j                  dd|j                  z  d      }t        |d      }t        ||j	                  |             t        t        | d      dd t        |      dd        y )	Nr   r   r   r"   r   r   r!   r#   )r>   r&   r   r   flipr  s       r   test_triangle_symmetryz+TestSawtoothWaveform.test_triangle_symmetry  s_    KK1RUU7D)Qc"2771:&!R(2.Ab0ABr   N)r   r   r   pytestmarkxfail_xp_backendsparametrizer   r   r  r	  r  r   r   r   r   r     s    [[""62I"J[[YI(>?[[]Y	,BCF D @ KF ;#
 [[""62I"JC KCr   r   c                   <   e Zd Zd Zej
                  j                  dd      ej
                  j                  dddg      ej
                  j                  dddg      d	                      Zej
                  j                  dd      ej
                  j                  d
g d      ej
                  j                  dg d      d                      Z	ej
                  j                  dddg      d        Z
d Zej
                  j                  dg d      d        Zy)TestSquareWaveformc                    |j                  ddt        j                  z  d      }t        |      }|j                  |j                  k(  sJ t        j
                  t        |            }t        |      j                  ddh      sJ y )Nr   r   r   ra   r.   )	r>   r$   r&   r
   shapeuniquer   setissubset)r7   r   r   r  r  s        r   test_uniquezTestSquareWaveform.test_unique  sk    KK1RUU7D)1Iww!''!!!,Q/06{##T3K000r   r   r   r   r   r   r   
duty_dtypec                     t        ||      }t        ||      }t        |j                  d|      |j                  d|            }|j                  |j	                  ||      k(  sJ y )Nr!   r   r"   duty)r   r
   r   r   r   )r7   r   r  r   r   s        r   r   zTestSquareWaveform.test_dtype  sc     "g&R,
"**Qg*6!zz#Zz@B~~!DDDDr   r   )Nr   r   r  )g?g      ?r"   g      ?c                    ||nt        ||      }|j                  d|      dz  dz  |j                  z  }t        ||      }|t	        |      n|}|j                  |j                  |dk(  |            }t        ||j                  ||      d          t        |j                  |      |j                  d|z  dz
  |      d          y )	Ng     @r   rn   r   r  r.   r   r!   )r   aranger&   r
   r	   meanr   r   )r7   r   r  r   r   r  fraction_highs          r   test_duty_cycle_fractionz+TestSquareWaveform.test_duty_cycle_fraction  s     GB,> IIfEI*U2Q6ruu<14 (- $5

185
 ABrzz$ez'DR'HI
BJJqvzJ$G$KLr   zduty, expected)r.   r.   )r   ra   c                     |j                  dd|j                  z  d      }t        ||      }t        ||j	                  |j
                  |             y )Nr   r   r;   r  )r>   r&   r
   r   fullr  )r7   r  r|   r   r   r  s         r   test_duty_edge_casesz'TestSquareWaveform.test_duty_edge_cases  sA    KK1RUU7C(14 277177H56r   c                     |j                  dd|j                  z  dd|j                        }t        |d      }t        |d|j                  z  z   d      }t	        ||       y )Nr   r   r   F)endpointr   r   r  )r>   r&   r   r
   r   r   s        r   r   z TestSquareWaveform.test_periodic  sT    KK1RUU7BbjjKIAC A"%%Kc*Br   )gg?r/   c                     |j                  ddt        j                  z  d      }t        ||      }|j	                  |j                  |            sJ y )Nr   r   r   r  )r>   r$   r&   r
   r  r  )r7   r  r   r   r  s        r   test_invalid_dutyz$TestSquareWaveform.test_invalid_duty  sB    KK1RUU7B'14 vvbhhqk"""r   N)r   r   r   r  r  r  r  r  r   r!  r$  r   r(  r   r   r   r  r    s)   1 [[""62I"J[[YI(>?[[\Iy+ABE C @ KE [[""62I"J[[W&BC[[V%;<
M = D K
M [[-)/DE7 F7
  [[V%56# 7#r   r  )T)numpyr$   r  r   r   scipy._lib._array_apir   r   r   r   r   r	   scipy.signal._waveformssignal
_waveformsr4   scipy.signalr
   r   r   r   r   r   r*   r,   r   r   r   r   r  r   r   r   <module>r/     s      * 
 , + )


	GC GCTA AHC C6#< #<L 8"C "C "CJ 63# 3# 3#r   