o
    1&iGF                     @   s  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 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"d/d0 Z#d1d2 Z$d3d4 Z%d5d6 Z&d7d8 Z'd9d: Z(d;d< Z)d=d> Z*d?d@ Z+dAdB Z,dCdD Z-dEdF Z.dGdH Z/dIdJ Z0dKdL Z1dMdN Z2dOdP Z3dQdR Z4dSdT Z5dUdV Z6G dWdX dXeZ7e8dYkre9  dS dS )Z    N)njittypes)TestCase)numpy_supportc                 C   
   t | S N)mathsinx r   CC:\wamp64\www\opt\env\Lib\site-packages\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   *   r   r   c                 C   r   r   )r   atanr
   r   r   r   r   .   r   r   c                 C      t | |S r   )r   atan2)yr   r   r   r   r   2      r   c                 C   r   r   )r   asinhr
   r   r   r   r   6   r   r   c                 C   r   r   )r   acoshr
   r   r   r   r   :   r   r   c                 C   r   r   )r   atanhr
   r   r   r   r   >   r   r   c                 C   r   r   r   sqrtr
   r   r   r   r   B   r   r   c                 C   r   r   )npr   r
   r   r   r   npy_sqrtF   r   r!   c                 C   r   r   )r   expr
   r   r   r   r"   J   r   r"   c                 C   r   r   )r   expm1r
   r   r   r   r#   N   r   r#   c                 C   r   r   )r   logr
   r   r   r   r$   R   r   r$   c                 C   r   r   )r   log1pr
   r   r   r   r%   V   r   r%   c                 C   r   r   )r   log10r
   r   r   r   r&   Z   r   r&   c                 C   r   r   )r   log2r
   r   r   r   r'   ^   r   r'   c                 C   r   r   )r   floorr
   r   r   r   r(   b   r   r(   c                 C   r   r   )r   ceilr
   r   r   r   r)   f   r   r)   c                 C   r   r   )r   truncr
   r   r   r   r*   j   r   r*   c                 C   r   r   )r   isnanr
   r   r   r   r+   n   r   r+   c                 C   r   r   )r   isinfr
   r   r   r   r,   r   r   r,   c                 C   r   r   )r   isfiniter
   r   r   r   r-   v   r   r-   c                 C   r   r   )r   hypotr   r   r   r   r   r.   z   r   r.   c                 C   r   r   )r   	nextafterr/   r   r   r   r0   ~   r   r0   c                 C   r   r   )r   degreesr
   r   r   r   r1      r   r1   c                 C   r   r   )r   radiansr
   r   r   r   r2      r   r2   c                 C   r   r   )r   erfr
   r   r   r   r3      r   r3   c                 C   r   r   )r   erfcr
   r   r   r   r4      r   r4   c                 C   r   r   )r   gammar
   r   r   r   r5      r   r5   c                 C   r   r   )r   lgammar
   r   r   r   r6      r   r6   c                 C   r   r   )r   powr/   r   r   r   r7      r   r7   c                 C   r   r   )r   gcdr/   r   r   r   r8      r   r8   c                 C   r   r   )r   copysignr/   r   r   r   r9      r   r9   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   r>   c                   @   s  e Zd Zdd Zd]ddZd]ddZdd	 Zd
d Ze	e
jdkd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 Z d8d9 Z!d:d; Z"d<d= Z#d>d? Z$d@dA Z%dBdC Z&dDdE Z'dFdG Z(dHdI Z)dJdK Z*dLdM Z+dNdO Z,dPdQ Z-dRdS Z.dTdU Z/dVdW Z0dXdY Z1dZd[ Z2d\S )^TestMathLibc                 C   s   t t}| | |  d S r   )r   r>   assertPreciseEqualZpy_func)selfcfuncr   r   r   test_constants   s   zTestMathLib.test_constantsexactc                 K   sf   t |}t||D ]'\}}||}	||}
|tju rdn|}d|f }| j|	|
f||d| q	d S )Nsinglefor input %rprecmsgr   zipr   float32r@   )rA   pyfuncx_typesx_valuesrH   kwargsrB   ZtxZvxgotexpectedactual_precrI   r   r   r   	run_unary   s   
zTestMathLib.run_unaryc                 C   sh   t |}t|||D ]'\}}}	|||	}
|||	}|tju r dn|}d||	f }| j|
|||d q
d S )NrE   zfor inputs (%r, %r)rG   rJ   )rA   rM   rN   rO   y_valuesrH   rB   tyr   r   rQ   rR   rS   rI   r   r   r   
run_binary   s   

zTestMathLib.run_binaryc                 C   sr   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uint64rL   float64floatrT   rA   rM   rN   rO   r   r   r   check_predicate_func   s   z TestMathLib.check_predicate_funcc                 C   B   t }tjtjtjtjtjtjtjtj	g}g d}| 
||| d S Nrh         rj   皙?皙?)r	   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   test_sin      zTestMathLib.test_sinwin32z'not exactly equal on win32 (issue #597)c                 C   re   rf   )r   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   test_cos   s   zTestMathLib.test_cosc                 C   re   rf   )r   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   test_tan   ro   zTestMathLib.test_tanc                 C   re   )Nrj   rk   rj   rj   rk   rj   rl   rm   )r   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   	test_sqrt   ro   zTestMathLib.test_sqrtc                 C   sX   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 )Nrs   rE   rH   )r!   r   r[   r^   rT   r\   r]   r_   r`   rL   ra   rA   rM   rO   rN   r   r   r   test_npy_sqrt   s   zTestMathLib.test_npy_sqrtc                 C   re   rf   )r"   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   test_exp   ro   zTestMathLib.test_expc                 C   re   rf   )r#   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   
test_expm1  ro   zTestMathLib.test_expm1c                 C   re   N)rk   
   d   i  i i@B rl   g?)r$   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   test_log  ro   zTestMathLib.test_logc                 C   re   rz   )r%   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   
test_log1p  ro   zTestMathLib.test_log1pc                 C   re   rz   )r&   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   
test_log10   ro   zTestMathLib.test_log10c                 C   re   rz   )r'   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   	test_log2(  ro   zTestMathLib.test_log2c                 C   re   Nrk   rk   rk   rk   rk   rk         ?r   )r   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   	test_asin0  ro   zTestMathLib.test_asinc                 C   re   r   )r   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   	test_acos8  ro   zTestMathLib.test_acosc                 C   re   rf   )r   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   	test_atan@  ro   zTestMathLib.test_atanc                 C   R   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 )Nrg   c                 S      g | ]}|d  qS rj   r   .0r   r   r   r   
<listcomp>N      z*TestMathLib.test_atan2.<locals>.<listcomp>)r   r   r[   r\   r]   r^   r_   r`   rL   ra   rW   rA   rM   rN   rO   rU   r   r   r   
test_atan2H     zTestMathLib.test_atan2c                 C   F   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   doubleru   )r   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   
test_asinhQ     zTestMathLib.test_asinhc                 C   re   r   )r   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   
test_acoshY  ro   zTestMathLib.test_acoshc                 C   r   )Nr   r   r   r   r   r   rl   rl   r   ru   )r   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   
test_atanha  r   zTestMathLib.test_atanhc                 C   re   r   )r   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   	test_sinhi  ro   zTestMathLib.test_sinhc                 C   re   r   )r   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   	test_coshq  ro   zTestMathLib.test_coshc                 C   re   )Nr   )r   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   	test_tanhy  ro   zTestMathLib.test_tanhc                 C   re   N)r   r   r   r   r   r   rl   gffffff?)r(   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   
test_floor  ro   zTestMathLib.test_floorc                 C   re   r   )r)   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   	test_ceil  ro   zTestMathLib.test_ceilc                 C   re   r   )r*   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   
test_trunc  ro   zTestMathLib.test_truncc                 C      |  t d S r   )rd   r+   rA   r   r   r   
test_isnan     zTestMathLib.test_isnanc                 C   r   r   )rd   r,   r   r   r   r   
test_isinf  r   zTestMathLib.test_isinfc                 C   r   r   )rd   r-   r   r   r   r   test_isfinite  r   zTestMathLib.test_isfinitec              	   C   s   t }tjtjtjtjg}g d}dd |D }d}| ||||| dd }t|}tjtjfD ]M}t	|j
}	|	t|	jd }
||
|
}| j|||
|
dd | t| t  td	t | td
||
|
 W d    n1 sxw   Y  q0d S )N)rk   rj               zG?(\?c                 S      g | ]}|d  qS r   r   r   r   r   r   r     r   z*TestMathLib.test_hypot.<locals>.<listcomp>rE   c                 S   s   t | |  ||  S r   r   r/   r   r   r   naive_hypot  s   z+TestMathLib.test_hypot.<locals>.naive_hypotg      >@ru   errorz overflow encountered in .*scalar)r.   r   r]   r`   rL   ra   rW   r   r   Zas_dtypetyper    Zfinfomaxr@   
assertTruer-   warningscatch_warningssimplefilterRuntimeWarningassertRaisesRegex)rA   rM   rN   rO   rU   rH   r   rB   flttydtvalZnb_ansr   r   r   
test_hypot  s2   

zTestMathLib.test_hypotc                 C   s   t }tjtjtjtjtjtjg}g d}dd |D }dd |D }| |||| | |||| | ||g dt	j
gd  | ||g dt	j
 gd  | |||| d S )N)rY   r   r   g%.AgS9c                 S   r   r   r   r   r   r   r   r     r   z.TestMathLib.test_nextafter.<locals>.<listcomp>c                 S   s   g | ]}|d  qS r   r   r   r   r   r   r     r   )rY               ?r   )r0   r   rL   ra   r\   r]   r_   r`   rW   r   rX   )rA   rM   rN   rO   Z	y1_valuesZ	y2_valuesr   r   r   test_nextafter  s   zTestMathLib.test_nextafterc                 C   re   r   )r1   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   test_degrees  ro   zTestMathLib.test_degreesc                 C   re   r   )r2   r   r[   r\   r]   r^   r_   r`   rL   ra   rT   rc   r   r   r   test_radians  ro   zTestMathLib.test_radiansc              	   C   sL   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                rY   r   r   rX   rj   r   rH   Zulps)r3   rb   r   rL   ra   lenrT   rv   r   r   r   test_erf     zTestMathLib.test_erfc              	   C   sL   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   rY   r   r   rX   rj   r   r   r   )r4   rb   r   rL   ra   r   rT   rv   r   r   r   	test_erfc  r   zTestMathLib.test_erfcc                 C   st   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   r   r   rj   r   r   r   皙rl         @g333333$@g      I@rX      )r5   r   rL   ra   r   rT   rb   rv   r   r   r   
test_gamma  s   zTestMathLib.test_gammac              	   C   sJ   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   rl   g      i@g    _Bgꌠ9Y>)FrX   rj   r   ru   )r6   rb   r   rL   ra   r   rT   rv   r   r   r   test_lgamma  s   zTestMathLib.test_lgammac                 C   r   )Nrg   c                 S   r   r   r   r   r   r   r   r     r   z(TestMathLib.test_pow.<locals>.<listcomp>)r7   r   r[   r\   r]   r^   r_   r`   rL   ra   rW   r   r   r   r   test_pow  r   zTestMathLib.test_powc           
      C   sx   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)rh   ri   r   rk   rj      r{   rj   )r   rk   rj   r   	      )	itertoolsr   r   r   r8   sortedr   Zsigned_domainZunsigned_domainrK   rW   )
rA   r   r   r   rM   Zsigned_argsZunsigned_argsrN   rO   rU   r   r   r   test_gcd  s   zTestMathLib.test_gcdc              
   C   sb   t }tjtjg}ddddddtdtdtd	g	}ttt||| \}}}| 	|||| d S )
Nrh   ri   r   rY   rk   rj   -infrX   rZ   )
r9   r   rL   ra   rb   listrK   r   r   rW   )rA   rM   Zvalue_typesvaluesrN   rO   rU   r   r   r   test_copysign  s   zTestMathLib.test_copysignc                 C   sD   t }tjtjg}ddddtdtdtdg}| j|||dd	 d S )
Ng      r   rY   g      @r   rX   rZ   rD   ru   )r:   r   rL   ra   rb   rT   rc   r   r   r   
test_frexp  s   zTestMathLib.test_frexpc                 C   st   t }t|}tjtjfD ]+}ddddddtddftd	dftd
dff	D ]}d|f }| || ||  q%qd S )N)r   rh   )r   rk   )rY   r   )rY   rk   )r   r   )r   rk   rX   r   r   rZ   rF   )r;   r   r   rL   ra   rb   r@   )rA   rM   rB   r   argsrI   r   r   r   
test_ldexp"  s   

zTestMathLib.test_ldexpN)rD   )3__name__
__module____qualname__rC   rT   rW   rd   rn   unittestZskipIfsysplatformrq   rr   rt   rw   rx   ry   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?      s`    


	

				r?   __main__):r   r   r   r   r   numpyr    Znumbar   r   Znumba.tests.supportr   Znumba.npr   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.   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r>   r?   r   mainr   r   r   r   <module>   sr       