
    piE                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZm	Z	 d dl
mZ d dlmZ d dlm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&d Z'd Z(d Z)d  Z*d! Z+d" Z,d# Z-d$ Z.d% Z/d& Z0d' Z1d( Z2d) Z3d* Z4d+ Z5d, Z6d- Z7d. Z8d/ Z9 G d0 d1e      Z:e;d2k(  r ejx                          yy)3    N)njittypes)TestCase)numpy_support)	PYVERSIONc                 ,    t        j                  |       S N)mathsinxs    Z/opt/services/ai/voice_agent/venv/lib/python3.12/site-packages/numba/tests/test_mathlib.pyr   r          88A;    c                 ,    t        j                  |       S r	   )r
   cosr   s    r   r   r      r   r   c                 ,    t        j                  |       S r	   )r
   tanr   s    r   r   r      r   r   c                 ,    t        j                  |       S r	   )r
   sinhr   s    r   r   r          99Q<r   c                 ,    t        j                  |       S r	   )r
   coshr   s    r   r   r      r   r   c                 ,    t        j                  |       S r	   )r
   tanhr   s    r   r   r   #   r   r   c                 ,    t        j                  |       S r	   )r
   asinr   s    r   r   r   '   r   r   c                 ,    t        j                  |       S r	   )r
   acosr   s    r   r   r   +   r   r   c                 ,    t        j                  |       S r	   )r
   atanr   s    r   r!   r!   /   r   r   c                 .    t        j                  | |      S r	   )r
   atan2)yr   s     r   r#   r#   3       ::ar   c                 ,    t        j                  |       S r	   )r
   asinhr   s    r   r'   r'   7       ::a=r   c                 ,    t        j                  |       S r	   )r
   acoshr   s    r   r*   r*   ;   r(   r   c                 ,    t        j                  |       S r	   )r
   atanhr   s    r   r,   r,   ?   r(   r   c                 ,    t        j                  |       S r	   r
   sqrtr   s    r   r/   r/   C   r   r   c                 ,    t        j                  |       S r	   )npr/   r   s    r   npy_sqrtr2   G   s    771:r   c                 ,    t        j                  |       S r	   )r
   expr   s    r   r4   r4   K   r   r   c                 ,    t        j                  |       S r	   )r
   exp2r   s    r   r6   r6   N   r   r   c                 ,    t        j                  |       S r	   )r
   expm1r   s    r   r8   r8   Q   r(   r   c                 ,    t        j                  |       S r	   )r
   logr   s    r   r:   r:   U   r   r   c                 ,    t        j                  |       S r	   )r
   log1pr   s    r   r<   r<   Y   r(   r   c                 ,    t        j                  |       S r	   )r
   log10r   s    r   r>   r>   ]   r(   r   c                 ,    t        j                  |       S r	   )r
   log2r   s    r   r@   r@   a   r   r   c                 ,    t        j                  |       S r	   )r
   floorr   s    r   rB   rB   e   r(   r   c                 ,    t        j                  |       S r	   )r
   ceilr   s    r   rD   rD   i   r   r   c                 ,    t        j                  |       S r	   )r
   truncr   s    r   rF   rF   m   r(   r   c                 ,    t        j                  |       S r	   )r
   isnanr   s    r   rH   rH   q   r(   r   c                 ,    t        j                  |       S r	   )r
   isinfr   s    r   rJ   rJ   u   r(   r   c                 ,    t        j                  |       S r	   )r
   isfiniter   s    r   rL   rL   y   s    ==r   c                 .    t        j                  | |      S r	   )r
   hypotr   r$   s     r   rN   rN   }   r%   r   c                 .    t        j                  | |      S r	   )r
   	nextafterrO   s     r   rQ   rQ      s    >>!Qr   c                 ,    t        j                  |       S r	   )r
   degreesr   s    r   rS   rS          <<?r   c                 ,    t        j                  |       S r	   )r
   radiansr   s    r   rV   rV      rT   r   c                 ,    t        j                  |       S r	   )r
   erfr   s    r   rX   rX      r   r   c                 ,    t        j                  |       S r	   )r
   erfcr   s    r   rZ   rZ      r   r   c                 ,    t        j                  |       S r	   )r
   gammar   s    r   r\   r\      r(   r   c                 ,    t        j                  |       S r	   )r
   lgammar   s    r   r^   r^      s    ;;q>r   c                 .    t        j                  | |      S r	   )r
   powrO   s     r   r`   r`          88Aq>r   c                 .    t        j                  | |      S r	   )r
   gcdrO   s     r   rc   rc      ra   r   c                 .    t        j                  | |      S r	   )r
   copysignrO   s     r   re   re      s    ==Ar   c                 ,    t        j                  |       S r	   )r
   frexpr   s    r   rg   rg      r(   r   c                 .    t        j                  | |      S r	   )r
   ldexp)r   es     r   ri   ri      r%   r   c                  B    t         j                  t         j                  fS r	   )r
   pirj    r   r   get_constantsrn      s    77DFF?r   c                      e Zd Zd Zd3dZd3dZd Zd Z ej                  e
j                  dk(  d      d        Zd	 Zd
 Zd Zd Z ej"                  edk\  d      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)d& Z*d' Z+d( Z,d) Z-d* Z.d+ Z/d, Z0d- Z1d. Z2d/ Z3d0 Z4d1 Z5y2)4TestMathLibc                 l    t        t              }| j                   |       |j                                y r	   )r   rn   assertPreciseEqualpy_func)selfcfuncs     r   test_constantszTestMathLib.test_constants   s$    ]#9r   c                     t        |      }t        ||      D ]G  \  }} ||      }	 ||      }
|t        j                  u rdn|}d|} | j                  |	|
f||d| I y )Nsingle
for input precmsgr   zipr   float32rr   )rt   pyfuncx_typesx_valuesr{   kwargsru   txvxgotexpectedactual_precr|   s                r   	run_unaryzTestMathLib.run_unary   sv    V'8, 	.FB)CbzH&(EMM&9(tK$&(C#D##C . .&,.	.r   c                     t        |      }t        |||      D ]L  \  }}}	 |||	      }
 |||	      }|t        j                  u rdn|}d|d|	d}| j	                  |
|||       N y )Nrx   zfor inputs (z, )rz   r}   )rt   r   r   r   y_valuesr{   ru   tyr   r$   r   r   r   r|   s                 r   
run_binaryzTestMathLib.run_binary   st    VGXx8 	NHB11+Ca|H&(EMM&9(tK+,a0C##C#M	Nr   c                    t         j                  t         j                  t         j                  t         j                  t         j
                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  g}ddddddt        d      dt        d      t        d      dt        d      g}| j                  |||       y )Nr   inf        nan)r   int16int32int64uint16uint32uint64r   float64floatr   rt   r   r   r   s       r   check_predicate_funcz TestMathLib.check_predicate_func   s    ;;U[[<<u||==%--==%--@ q!Q1%L#uU|%L#uU|5 	vw1r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y Nr         r   皙?皙?)r   r   r   r   r   r   r   r   r   r   r   r   s       r   test_sinzTestMathLib.test_sin   X    ;;U[[<<u||==%--1 1vw1r   win32z'not exactly equal on win32 (issue #597)c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )r   r   r   r   r   r   r   r   r   r   r   r   s       r   test_coszTestMathLib.test_cos   sZ     ;;U[[<<u||==%--1 1vw1r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )r   r   r   r   r   r   r   r   r   r   r   r   s       r   test_tanzTestMathLib.test_tan   r   r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y )Nr   r   r   r   r   r   r   r   )r/   r   r   r   r   r   r   r   r   r   r   r   s       r   	test_sqrtzTestMathLib.test_sqrt   X    ;;U[[<<u||==%--1 .vw1r   c                 `   t         }g d}t        j                  t        j                  g}| j	                  |||d       t        j
                  t        j                  t        j                  t        j                  t        j                  t        j                  g}| j	                  |||       y )Nr   rx   r{   )r2   r   r   r   r   r   r   r   r   r   r   rt   r   r   r   s       r   test_npy_sqrtzTestMathLib.test_npy_sqrt   sr    -;;-vwx@;;<<==%--1 	vw1r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )r4   r   r   r   r   r   r   r   r   r   r   r   s       r   test_expzTestMathLib.test_exp  r   r   )      zneeds Python 3.11+c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )r6   r   r   r   r   r   r   r   r   r   r   r   s       r   	test_exp2zTestMathLib.test_exp2  sX    ;;U[[<<u||==%--1 1vw1r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )r8   r   r   r   r   r   r   r   r   r   r   r   s       r   
test_expm1zTestMathLib.test_expm1  sX    ;;U[[<<u||==%--1 1vw1r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y N)r   
   d   i  i i@B r   g?)r:   r   r   r   r   r   r   r   r   r   r   r   s       r   test_logzTestMathLib.test_log  sY    ;;U[[<<u||==%--1 Avw1r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )r<   r   r   r   r   r   r   r   r   r   r   r   s       r   
test_log1pzTestMathLib.test_log1p$  Y    ;;U[[<<u||==%--1 Avw1r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )r>   r   r   r   r   r   r   r   r   r   r   r   s       r   
test_log10zTestMathLib.test_log10,  r   r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )r@   r   r   r   r   r   r   r   r   r   r   r   s       r   	test_log2zTestMathLib.test_log24  sY    ;;U[[<<u||==%--1 Avw1r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y Nr   r   r   r   r   r         ?r   )r   r   r   r   r   r   r   r   r   r   r   r   s       r   	test_asinzTestMathLib.test_asin<  r   r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )r   r   r   r   r   r   r   r   r   r   r   r   s       r   	test_acoszTestMathLib.test_acosD  r   r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )r!   r   r   r   r   r   r   r   r   r   r   r   s       r   	test_atanzTestMathLib.test_atanL  sX    ;;U[[<<u||==%--1 1vw1r   c                 b   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}|D cg c]  }|dz  	 }}| j                  ||||       y c c}w Nr   r   )r#   r   r   r   r   r   r   r   r   r   r   rt   r   r   r   r   r   s         r   
test_atan2zTestMathLib.test_atan2T  sv    ;;U[[<<u||==%--1 1#+,aAE,,8< -   	B,c                 6   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||d       y )Nr   doubler   )r'   r   r   r   r   r   r   r   r   r   r   r   s       r   
test_asinhzTestMathLib.test_asinh]  s\    ;;U[[<<u||==%--1 .vwx@r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )r*   r   r   r   r   r   r   r   r   r   r   r   s       r   
test_acoshzTestMathLib.test_acoshe  sX    ;;U[[<<u||==%--1 .vw1r   c                 6   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||d       y )Nr   r   r   r   r   r   r   r   r   r   )r,   r   r   r   r   r   r   r   r   r   r   r   s       r   
test_atanhzTestMathLib.test_atanhm  s\    ;;U[[<<u||==%--1 0vwx@r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )r   r   r   r   r   r   r   r   r   r   r   r   s       r   	test_sinhzTestMathLib.test_sinhu  r   r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )r   r   r   r   r   r   r   r   r   r   r   r   s       r   	test_coshzTestMathLib.test_cosh}  r   r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y )Nr   )r   r   r   r   r   r   r   r   r   r   r   r   s       r   	test_tanhzTestMathLib.test_tanh  X    ;;U[[<<u||==%--1 0vw1r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y N)r   r   r   r   r   r   r   gffffff?)rB   r   r   r   r   r   r   r   r   r   r   r   s       r   
test_floorzTestMathLib.test_floor  X    ;;U[[<<u||==%--1 0vw1r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )rD   r   r   r   r   r   r   r   r   r   r   r   s       r   	test_ceilzTestMathLib.test_ceil  r   r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )rF   r   r   r   r   r   r   r   r   r   r   r   s       r   
test_trunczTestMathLib.test_trunc  r   r   c                 .    | j                  t               y r	   )r   rH   rt   s    r   
test_isnanzTestMathLib.test_isnan      !!%(r   c                 .    | j                  t               y r	   )r   rJ   r   s    r   
test_isinfzTestMathLib.test_isinf  r   r   c                 .    | j                  t               y r	   )r   rL   r   s    r   test_isfinitezTestMathLib.test_isfinite  s    !!(+r   c           	      ,   t         }t        j                  t        j                  t        j                  t        j
                  g}g d}|D cg c]  }|dz   	 }}d}| j                  |||||       d }t        |      }t        j                  t        j
                  fD ]  }	t        j                  |	      j                  }
 |
t        j                  |
      j                  dz        } |||      }| j                  | |||      d       | j                  t        j                   |             t#        j$                         5  t#        j&                  dt(               | j+                  t(        d|||       d d d         y c c}w # 1 sw Y   xY w)	N)r   r   r            zG?(\?r   rx   c                 >    t        j                  | | z  ||z  z         S r	   r.   rO   s     r   naive_hypotz+TestMathLib.test_hypot.<locals>.naive_hypot  s    99QUQU]++r   g      >@r   errorz overflow encountered in .*scalar)rN   r   r   r   r   r   r   r   r   as_dtypetyper1   finfomaxrr   
assertTruerL   warningscatch_warningssimplefilterRuntimeWarningassertRaisesRegex)rt   r   r   r   r   r   r{   r   ru   flttydtvalnb_anss                r   
test_hypotzTestMathLib.test_hypot  sM   ;;==%--1/#+,aAE,,8TB	, VmmU]]3 	?E''.33BRXXb\%%+,C3_F##FF3,<8#LOOBKK/0((* ?%%g~>&&~(J(3S#?? ?	? -$? ?s   F4F

F	c                 F   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  g}g d}|D cg c]  }|dz   	 }}|D cg c]  }|dz
  	 }}| j                  ||||       | j                  ||||       | j                  ||g dt        j                  gdz         | j                  ||g dt        j                   gdz         | j                  ||||       y c c}w c c}w )N)r   r   r   g%.AgS9r   )r               ?r   )rQ   r   r   r   r   r   r   r   r   r
   r   )rt   r   r   r   r   	y1_values	y2_valuess          r   test_nextafterzTestMathLib.test_nextafter  s    ==%--;;<</ 9$,-qQU-	-$,-qQU-	-9=9= 	$((AF488)QG 	8< .-s   +D=Dc                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )rS   r   r   r   r   r   r   r   r   r   r   r   s       r   test_degreeszTestMathLib.test_degrees  X    ;;U[[<<u||==%--1 .vw1r   c                 2   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}| j                  |||       y r   )rV   r   r   r   r   r   r   r   r   r   r   r   s       r   test_radianszTestMathLib.test_radians  r  r   c           
          t         }dddddddt        d      g}t        j                  t        j                  gt        |      dz  z  }| j                  |||d	d
       y )Nr                r   r  r   r   r   r   r{   ulps)rX   r   r   r   r   lenr   r   s       r   test_erfzTestMathLib.test_erf  sW    CsCE%LA==%--0CMQ4FGvwxaHr   c           
          t         }dddddddt        d      g}t        j                  t        j                  gt        |      dz  z  }| j                  |||d	d
       y )Nr   r  r  r   r  r   r   r   r   r   r  )rZ   r   r   r   r   r  r   r   s       r   	test_erfczTestMathLib.test_erfc  sW    CsCE%LA==%--0CMQ4FGvwxaHr   c                 *   t         }g d}t        j                  t        j                  gt	        |      dz  z  }| j                  |||dd       dddd	d
t        d      g}t        j                  gt	        |      z  }| j                  |||dd       y )N)r   r  r  r   r   r   r  皙r         @g333333$@g      I@r      )r\   r   r   r   r  r   r   r   s       r   
test_gammazTestMathLib.test_gamma  s    (==%--0CMQ4FGvwxaH#sD#uU|<==/CM1vwxaHr   c           
          t         }dddddddt        d      g}t        j                  t        j                  gt        |      d	z  z  }| j                  |||d
       y )Nr   r#  r$  r   g      i@g    _Bgꌠ9Y>)Fr   r   r   r   )r^   r   r   r   r   r  r   r   s       r   test_lgammazTestMathLib.test_lgamma  sU    dCtT5<H==%--0CMQ4FGvwx@r   c                 b   t         }t        j                  t        j                  t        j                  t        j
                  t        j                  t        j                  t        j                  t        j                  g}g d}|D cg c]  }|dz  	 }}| j                  ||||       y c c}w r   )r`   r   r   r   r   r   r   r   r   r   r   r   s         r   test_powzTestMathLib.test_pow	  sv    ;;U[[<<u||==%--1 1#+,aAE,,8< -r   c                    ddl m}m}m} t        } |t        t        j                        g |dd       } |t        t        j                        g |dd       }t         |||       \  }}}	| j                  ||||	       y )Nr   )productrepeatchain)r   r   r   r   r      r   r   )r   r   r   r0  	      )	itertoolsr-  r.  r/  rc   sortedr   signed_domainunsigned_domainr~   r   )
rt   r-  r.  r/  r   signed_argsunsigned_argsr   r   r   s
             r   test_gcdzTestMathLib.test_gcd  s    445&&'
*01I1*M
  5(()
,23F,J
 '*5m+L&M#88<r   c                    t         }t        j                  t        j                  g}ddddddt	        d      t	        d      t	        d	      g	}t        t        t        j                  |||             \  }}}| j                  ||||       y )
Nr   r   r  r   r   r   -infr   r   )
re   r   r   r   r   listr~   r3  r-  r   )rt   r   value_typesvaluesr   r   r   s          r   test_copysignzTestMathLib.test_copysign  s|    }}emm4b$Q5=%,, &*3{FF;,= '>#88<r   c           	          t         }t        j                  t        j                  g}ddddt	        d      t	        d      t	        d      g}| j                  |||d	       y )
Ng      r  r   g      @r;  r   r   exactr   )rg   r   r   r   r   r   r   s       r   
test_frexpzTestMathLib.test_frexp'  sP    ==%--0$S&M5<u?vww?r   c                    t         }t        |      }t        j                  t        j                  fD ]P  }ddddddt        d      dft        d	      dft        d
      dff	D ]  }d|}| j                   ||  ||        ! R y )N)r%  r   )r%  r   )r   r   )r   r   )r  r   )r  r   r   r   r;  r   ry   )ri   r   r   r   r   r   rr   )rt   r   ru   r	  argsr|   s         r   
test_ldexpzTestMathLib.test_ldexp.  s    VmmU]]3 	EE"Hh"I,*U6]A,>,*, E )-.''tfdmDE	Er   N)rA  )6__name__
__module____qualname__rv   r   r   r   r   unittestskipIfsysplatformr   r   r   r   r   
skipUnlessr   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+  r9  r?  rB  rE  rm   r   r   rp   rp      s;   :.N22 X__S\\W,>@2@222	22 Xg-/CD2 E222222222=A2A222222)),?:=&22IIIA=
==@	Er   rp   __main__)=r3  r
   rK  rI  r  numpyr1   numbar   r   numba.tests.supportr   numba.npr   numba.core.utilsr   r   r   r   r   r   r   r   r   r!   r#   r'   r*   r,   r/   r2   r4   r6   r8   r:   r<   r>   r@   rB   rD   rF   rH   rJ   rL   rN   rQ   rS   rV   rX   rZ   r\   r^   r`   rc   re   rg   ri   rn   rp   rF  mainrm   r   r   <module>rU     s      
     ( " & DE( DEN zHMMO r   