o
    8ήcR                     @   s  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
mZ d dlmZmZ d dlmZmZmZ d dlZd dlmZ e Zde_e Zdd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Z dd Z!dd Z"dd Z#dd Z$d d! Z%d"d# Z&d$d% Z'd&d' Z(d(d) Z)d*d+ Z*d,d- Z+d.d/ Z,d0d1 Z-d2d3 Z.d4d5 Z/d6d7 Z0d8d9 Z1d:d; Z2d<d= Z3d>d? Z4d@dA Z5dBdC Z6dDdE Z7dFdG Z8dHdI Z9dJdK Z:dLdM Z;dNdO Z<dPdQ Z=dRdS Z>dTdU Z?G dVdW dWeZ@eAdXkreB  dS dS )Y    N)compile_isolatedFlags)utilstypes)IS_WIN32	IS_32BITS)TestCaseCompilationCachetag)numpy_supportTc                 C   
   t | S N)mathsinx r   ?/tmp/pip-target-vg8gfxp4/lib/python/numba/tests/test_mathlib.pyr         
r   c                 C   r   r   )r   cosr   r   r   r   r      r   r   c                 C   r   r   )r   tanr   r   r   r   r      r   r   c                 C   r   r   )r   sinhr   r   r   r   r   !   r   r   c                 C   r   r   )r   coshr   r   r   r   r   %   r   r   c                 C   r   r   )r   tanhr   r   r   r   r   )   r   r   c                 C   r   r   )r   asinr   r   r   r   r   -   r   r   c                 C   r   r   )r   acosr   r   r   r   r   1   r   r   c                 C   r   r   )r   atanr   r   r   r   r   5   r   r   c                 C      t | |S r   )r   atan2)yr   r   r   r   r   9      r   c                 C   r   r   )r   asinhr   r   r   r   r!   =   r   r!   c                 C   r   r   )r   acoshr   r   r   r   r"   A   r   r"   c                 C   r   r   )r   atanhr   r   r   r   r#   E   r   r#   c                 C   r   r   r   sqrtr   r   r   r   r%   I   r   r%   c                 C   r   r   )npr%   r   r   r   r   npy_sqrtM   r   r'   c                 C   r   r   )r   expr   r   r   r   r(   Q   r   r(   c                 C   r   r   )r   expm1r   r   r   r   r)   U   r   r)   c                 C   r   r   )r   logr   r   r   r   r*   Y   r   r*   c                 C   r   r   )r   log1pr   r   r   r   r+   ]   r   r+   c                 C   r   r   )r   log10r   r   r   r   r,   a   r   r,   c                 C   r   r   )r   floorr   r   r   r   r-   e   r   r-   c                 C   r   r   )r   ceilr   r   r   r   r.   i   r   r.   c                 C   r   r   )r   truncr   r   r   r   r/   m   r   r/   c                 C   r   r   )r   isnanr   r   r   r   r0   q   r   r0   c                 C   r   r   )r   isinfr   r   r   r   r1   u   r   r1   c                 C   r   r   )r   isfiniter   r   r   r   r2   y   r   r2   c                 C   r   r   )r   hypotr   r   r   r   r   r3   }   r    r3   c                 C   r   r   )r   degreesr   r   r   r   r5      r   r5   c                 C   r   r   )r   radiansr   r   r   r   r6      r   r6   c                 C   r   r   )r   erfr   r   r   r   r7      r   r7   c                 C   r   r   )r   erfcr   r   r   r   r8      r   r8   c                 C   r   r   )r   gammar   r   r   r   r9      r   r9   c                 C   r   r   )r   lgammar   r   r   r   r:      r   r:   c                 C   r   r   )r   powr4   r   r   r   r;      r    r;   c                 C   r   r   )r   gcdr4   r   r   r   r<      r    r<   c                 C   r   r   )r   copysignr4   r   r   r   r=      r    r=   c                 C   r   r   )r   frexpr   r   r   r   r>      r   r>   c                 C   r   r   )r   ldexp)r   er   r   r   r?      r    r?   c                   C   s   t jt jfS r   )r   pir@   r   r   r   r   get_constants   r    rB   c                   @   sB  e Zd Zdd Zdd ZedfddZedfdd	Zefd
dZefddZ	dd Z
eejdkdefddZdd ZefddZdd ZefddZdd ZefddZd d! Zefd"d#Zd$d% Zefd&d'Zd(d) Zefd*d+Zd,d- Zefd.d/Zd0d1 Zefd2d3Zd4d5 Z efd6d7Z!d8d9 Z"efd:d;Z#d<d= Z$efd>d?Z%d@dA Z&efdBdCZ'dDdE Z(efdFdGZ)dHdI Z*efdJdKZ+dLdM Z,efdNdOZ-dPdQ Z.efdRdSZ/dTdU Z0efdVdWZ1dXdY Z2efdZd[Z3d\d] Z4efd^d_Z5d`da Z6efdbdcZ7ddde Z8efdfdgZ9dhdi Z:djdk Z;dldm Z<dndo Z=dpdq Z>drds Z?dtdu Z@efdvdwZAdxdy ZBefdzd{ZCd|d} ZDefd~dZEdd ZFefddZGdd ZHefddZIdd ZJefddZKdd ZLefddZMdd ZNefddZOefddZPdd ZQdd ZRefddZSdd ZTefddZUdd ZVefddZWdd ZXdS )TestMathLibc                 C   s   t  | _d S r   )r	   ccacheselfr   r   r   setUp   r    zTestMathLib.setUpc                 C   s   |  tt d S r   )run_nullary_funcrB   no_pyobj_flagsrE   r   r   r   test_constants      zTestMathLib.test_constantsexactc                 K   sx   t ||D ]4\}}| jj||f|d}	|	j}
|
|}||}|tju r%dn|}d|f }| j||f||d| qd S )Nflagssinglefor input %rprecmsgziprD   compileentry_pointr   float32assertPreciseEqual)rF   pyfuncx_typesx_valuesrN   rR   kwargstxvxcrcfuncgotexpectedactual_precrS   r   r   r   	run_unary   s   
zTestMathLib.run_unaryc                 C   s|   t |||D ]5\}}}	| jj|||f|d}
|
j}|||	}|||	}|tju r*dn|}d||	f }| j||||d qd S )NrM   rO   zfor inputs (%r, %r)rQ   rT   )rF   rZ   r[   r\   y_valuesrN   rR   tyr   r   r`   ra   rb   rc   rd   rS   r   r   r   
run_binary   s   

zTestMathLib.run_binaryc                 C   st   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}| 
|||| d S )Nr   inf        nan)r   int16int32int64uint16uint32uint64rX   float64floatre   )rF   rZ   rN   r[   r\   r   r   r   check_predicate_func   s   z TestMathLib.check_predicate_funcc                 C   D   t }tjtjtjtjtjtjtjtj	g}g d}| 
|||| d S Nrx         rz   皙?皙?)r   r   rl   rm   rn   ro   rp   rq   rX   rr   re   rF   rN   rZ   r[   r\   r   r   r   test_sin      zTestMathLib.test_sinc                 C      | j td d S NrM   )r   rI   rE   r   r   r   test_sin_npm   rK   zTestMathLib.test_sin_npmwin32z'not exactly equal on win32 (issue #597)c                 C   ru   rv   )r   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   test_cos   s   zTestMathLib.test_cosc                 C   r   r   )r   rI   rE   r   r   r   test_cos_npm   rK   zTestMathLib.test_cos_npmc                 C   ru   rv   )r   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   test_tan   r   zTestMathLib.test_tanc                 C   r   r   )r   rI   rE   r   r   r   test_tan_npm   rK   zTestMathLib.test_tan_npmc                 C   ru   )Nrz   r{   rz   rz   r{   rz   r|   r}   )r%   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   	test_sqrt   r   zTestMathLib.test_sqrtc                 C   r   r   )r   rI   rE   r   r   r   test_sqrt_npm  rK   zTestMathLib.test_sqrt_npmc                 C   s\   t }g d}tjtjg}| j||||dd tjtjtjtjtj	tj
g}| |||| d S )Nr   rO   rR   )r'   r   rl   ro   re   rm   rn   rp   rq   rX   rr   rF   rN   rZ   r\   r[   r   r   r   test_npy_sqrt  s   zTestMathLib.test_npy_sqrtc                 C   r   r   )r   rI   rE   r   r   r   test_npy_sqrt_npm  rK   zTestMathLib.test_npy_sqrt_npmc                 C   ru   rv   )r(   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   test_exp  r   zTestMathLib.test_expc                 C   r   r   )r   rI   rE   r   r   r   test_exp_npm  rK   zTestMathLib.test_exp_npmc                 C   ru   rv   )r)   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   
test_expm1  r   zTestMathLib.test_expm1c                 C   r   r   )r   rI   rE   r   r   r   test_expm1_npm'  rK   zTestMathLib.test_expm1_npmc                 C   ru   N)r{   
   d   i  i i@B r|   g?)r*   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   test_log*  r   zTestMathLib.test_logc                 C   r   r   )r   rI   rE   r   r   r   test_log_npm2  rK   zTestMathLib.test_log_npmc                 C   ru   r   )r+   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   
test_log1p5  r   zTestMathLib.test_log1pc                 C   r   r   )r   rI   rE   r   r   r   test_log1p_npm=  rK   zTestMathLib.test_log1p_npmc                 C   ru   r   )r,   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   
test_log10@  r   zTestMathLib.test_log10c                 C   r   r   )r   rI   rE   r   r   r   test_log10_npmH  rK   zTestMathLib.test_log10_npmc                 C   ru   Nr{   r{   r{   r{   r{   r{         ?r   )r   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   	test_asinK  r   zTestMathLib.test_asinc                 C   r   r   )r   rI   rE   r   r   r   test_asin_npmS  rK   zTestMathLib.test_asin_npmc                 C   ru   r   )r   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   	test_acosV  r   zTestMathLib.test_acosc                 C   r   r   )r   rI   rE   r   r   r   test_acos_npm^  rK   zTestMathLib.test_acos_npmc                 C   ru   rv   )r   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   	test_atana  r   zTestMathLib.test_atanc                 C   r   r   )r   rI   rE   r   r   r   test_atan_npmi  rK   zTestMathLib.test_atan_npmc                 C   T   t }tjtjtjtjtjtjtjtj	g}g d}dd |D }| 
||||| d S )Nrw   c                 S      g | ]}|d  qS rz   r   .0r   r   r   r   
<listcomp>r      z*TestMathLib.test_atan2.<locals>.<listcomp>)r   r   rl   rm   rn   ro   rp   rq   rX   rr   rh   rF   rN   rZ   r[   r\   rf   r   r   r   
test_atan2l     zTestMathLib.test_atan2c                 C   r   r   )r   rI   rE   r   r   r   test_atan2_npmu  rK   zTestMathLib.test_atan2_npmc                 C   H   t }tjtjtjtjtjtjtjtj	g}g d}| j
||||dd d S )Nr   doubler   )r!   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   
test_asinhx     zTestMathLib.test_asinhc                 C   r   r   )r   rI   rE   r   r   r   test_asinh_npm  rK   zTestMathLib.test_asinh_npmc                 C   ru   r   )r"   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   
test_acosh  r   zTestMathLib.test_acoshc                 C   r   r   )r   rI   rE   r   r   r   test_acosh_npm  rK   zTestMathLib.test_acosh_npmc                 C   r   )Nr   r   r   r   r   r   r|   r|   r   r   )r#   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   
test_atanh  r   zTestMathLib.test_atanhc                 C   r   r   )r   rI   rE   r   r   r   test_atanh_npm  rK   zTestMathLib.test_atanh_npmc                 C   ru   r   )r   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   	test_sinh  r   zTestMathLib.test_sinhc                 C   r   r   )r   rI   rE   r   r   r   test_sinh_npm  rK   zTestMathLib.test_sinh_npmc                 C   ru   r   )r   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   	test_cosh  r   zTestMathLib.test_coshc                 C   r   r   )r   rI   rE   r   r   r   test_cosh_npm  rK   zTestMathLib.test_cosh_npmc                 C   ru   )Nr   )r   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   	test_tanh  r   zTestMathLib.test_tanhc                 C   r   r   )r   rI   rE   r   r   r   test_tanh_npm  rK   zTestMathLib.test_tanh_npmc                 C   ru   N)r   r   r   r   r   r   r|   gffffff?)r-   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   
test_floor  r   zTestMathLib.test_floorc                 C   r   r   )r   rI   rE   r   r   r   test_floor_npm  rK   zTestMathLib.test_floor_npmc                 C   ru   r   )r.   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   	test_ceil  r   zTestMathLib.test_ceilc                 C   r   r   )r   rI   rE   r   r   r   test_ceil_npm  rK   zTestMathLib.test_ceil_npmc                 C   ru   r   )r/   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   
test_trunc  r   zTestMathLib.test_truncc                 C   r   r   )r   rI   rE   r   r   r   test_trunc_npm  rK   zTestMathLib.test_trunc_npmc                 C      | j ttd d S r   )rt   r0   enable_pyobj_flagsrE   r   r   r   
test_isnan     zTestMathLib.test_isnanc                 C   r   r   )rt   r0   rI   rE   r   r   r   test_isnan_npm  r   zTestMathLib.test_isnan_npmc                 C   r   r   )rt   r1   r   rE   r   r   r   
test_isinf  r   zTestMathLib.test_isinfc                 C   r   r   )rt   r1   rI   rE   r   r   r   test_isinf_npm  r   zTestMathLib.test_isinf_npmc                 C   r   r   )rt   r2   r   rE   r   r   r   test_isfinite  r   zTestMathLib.test_isfinitec                 C   r   r   )rt   r2   rI   rE   r   r   r   test_isfinite_npm  r   zTestMathLib.test_isfinite_npmc              	   C   s  t }tjtjtjtjg}g d}dd |D }d}| |||||| dd }tjtjfD ][}| jj|||f|d}	|	j	}
t
|j}|t|jd }|
||}| j||||dd	 | t| t  td
t | td||| W d    n1 sw   Y  q-d S )N)r{   rz               gzG?g(\?c                 S   s   g | ]}|d  qS r   r   r   r   r   r   r     r   z*TestMathLib.test_hypot.<locals>.<listcomp>rO   c                 S   s   t | |  ||  S r   r$   r4   r   r   r   naive_hypot  s   z+TestMathLib.test_hypot.<locals>.naive_hypotrM   g      >@r   errorz"overflow encountered in .*_scalars)r3   r   rn   rq   rX   rr   rh   rD   rV   rW   r   as_dtypetyper&   finfomaxrY   
assertTruer2   warningscatch_warningssimplefilterRuntimeWarningassertRaisesRegexp)rF   rN   rZ   r[   r\   rf   rR   r   flttyr`   ra   dtvalnb_ansr   r   r   
test_hypot  s4   

zTestMathLib.test_hypotc                 C   r   r   )r   rI   rE   r   r   r   test_hypot_npm
  rK   zTestMathLib.test_hypot_npmc                 C   ru   r   )r5   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   test_degrees  r   zTestMathLib.test_degreesc                 C   r   r   )r   rI   rE   r   r   r   test_degrees_npm  rK   zTestMathLib.test_degrees_npmc                 C   ru   r   )r6   r   rl   rm   rn   ro   rp   rq   rX   rr   re   r~   r   r   r   test_radians  r   zTestMathLib.test_radiansc                 C   r   r   )r   rI   rE   r   r   r   test_radians_npm   rK   zTestMathLib.test_radians_npmc              	   C   sN   t }dddddddtdg}tjtjgt|d  }| j||||d	dd
 d S )Nr                rj         ?r   ri   rz   r   rR   ulps)r7   rs   r   rX   rr   lenre   r   r   r   r   test_erf#     
zTestMathLib.test_erfc                 C   r   r   )r   rI   rE   r   r   r   test_erf_npm*  rK   zTestMathLib.test_erf_npmc              	   C   sN   t }dddddddtdg}tjtjgt|d  }| j||||d	d
d d S )Nr   r   r   rj   r   r   ri   rz   r   r   r   )r8   rs   r   rX   rr   r   re   r   r   r   r   	test_erfc-  r   zTestMathLib.test_erfcc                 C   r   r   )r   rI   rE   r   r   r   test_erfc_npm4  rK   zTestMathLib.test_erfc_npmc                 C   sx   t }g d}tjtjgt|d  }| j||||ddd dddd	d
tdg}tjgt| }| j||||ddd d S )N)r   g      r   rz   r   r   r   皙r|         @g333333$@g      I@ri      )r9   r   rX   rr   r   re   rs   r   r   r   r   
test_gamma7  s   
zTestMathLib.test_gammac                 C   r   r   )r   rI   rE   r   r   r   test_gamma_npmA  rK   zTestMathLib.test_gamma_npmc              	   C   sL   t }dddddddtdg}tjtjgt|d	  }| j||||d
d d S )Nr   r   r   r|   g      i@g    _Bgꌠ9Y>)Fri   rz   r   r   )r:   rs   r   rX   rr   r   re   r   r   r   r   test_lgammaD  s   zTestMathLib.test_lgammac                 C   r   r   )r   rI   rE   r   r   r   test_lgamma_npmJ  rK   zTestMathLib.test_lgamma_npmc                 C   r   )Nrw   c                 S   r   r   r   r   r   r   r   r   S  r   z(TestMathLib.test_pow.<locals>.<listcomp>)r;   r   rl   rm   rn   ro   rp   rq   rX   rr   rh   r   r   r   r   test_powM  r   zTestMathLib.test_powc                 C   sz   ddl m}m}m} t}|ttjg|ddR  }|ttjg|ddR  }t	||| \}}	}
| 
|||	|
| d S )Nr   )productrepeatchain)rx   ry   r   r{   rz      r   rz   )r   r{   rz   r  	      )	itertoolsr   r   r  r<   sortedr   signed_domainunsigned_domainrU   rh   )rF   rN   r   r   r  rZ   signed_argsunsigned_argsr[   r\   rf   r   r   r   test_gcdV  s   zTestMathLib.test_gcdc                 C   r   r   )r  rI   rE   r   r   r   test_gcd_npmb  rK   zTestMathLib.test_gcd_npmc                 C   r   r   )r   rI   rE   r   r   r   test_pow_npme  rK   zTestMathLib.test_pow_npmc              
   C   sd   t }tjtjg}ddddddtdtdtd	g	}ttt||| \}}}| 	||||| d S )
Nrx   ry   r   rj   r{   rz   -infri   rk   )
r=   r   rX   rr   rs   listrU   r  r   rh   )rF   rN   rZ   value_typesvaluesr[   r\   rf   r   r   r   test_copysignh  s   zTestMathLib.test_copysignc                 C   r   r   )r  rI   rE   r   r   r   test_copysign_npmq  rK   zTestMathLib.test_copysign_npmc                 C   sF   t }tjtjg}ddddtdtdtdg}| j||||dd	 d S )
Ng      r   rj   g      @r  ri   rk   rL   r   )r>   r   rX   rr   rs   re   r~   r   r   r   
test_frexpt  s   zTestMathLib.test_frexpc                 C   r   r   )r  rI   rE   r   r   r   test_frexp_npm{  rK   zTestMathLib.test_frexp_npmc                 C   s   t }tjtjfD ]:}| jj||tjf|d}|j}ddddddtdd	ftd
d	ftdd	ff	D ]}d|f }| 	|| ||  q0qd S )NrM   )r   rx   )r   r{   )rj   r   )rj   r{   )r   r   )r   r{   ri   r   r  rk   rP   )
r?   r   rX   rr   rD   rV   rm   rW   rs   rY   )rF   rN   rZ   r   r`   ra   argsrS   r   r   r   
test_ldexp~  s   

zTestMathLib.test_ldexpc                 C   r   r   )r  rI   rE   r   r   r   test_ldexp_npm  rK   zTestMathLib.test_ldexp_npmN)Y__name__
__module____qualname__rG   rJ   r   re   rh   rt   r   r   unittestskipIfsysplatformr   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   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   r  r  r  r  r  r  r  r  r  r   r   r   r   rC      s    


	
		rC   __main__)Cr  r   r  r   numpyr&   numba.core.compilerr   r   
numba.corer   r   numba.core.configr   r   numba.tests.supportr   r	   r
   r  numba.npr   r   enable_pyobjectrI   r   r   r   r   r   r   r   r   r   r   r!   r"   r#   r%   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   rB   rC   r  mainr   r   r   r   <module>   sx       b