o
    iE                     @   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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$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 Z0dHdI Z1dJdK Z2dLdM Z3dNdO Z4dPdQ Z5dRdS Z6dTdU Z7dVdW Z8dXdY Z9G dZd[ d[eZ:e;d\kre<  dS dS )]    N)njittypes)TestCase)numpy_support)	PYVERSIONc                 C   
   t | S N)mathsinx r   V/home/ubuntu/transcripts/venv/lib/python3.10/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   3      r   c                 C   r   r   )r	   asinhr   r   r   r   r   7   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    C   r   r    c                 C   r   r   )npr    r   r   r   r   npy_sqrtG   r   r"   c                 C   r   r   )r	   expr   r   r   r   r#   K   r   r#   c                 C   r   r   )r	   exp2r   r   r   r   r$   N   r   r$   c                 C   r   r   )r	   expm1r   r   r   r   r%   Q   r   r%   c                 C   r   r   )r	   logr   r   r   r   r&   U   r   r&   c                 C   r   r   )r	   log1pr   r   r   r   r'   Y   r   r'   c                 C   r   r   )r	   log10r   r   r   r   r(   ]   r   r(   c                 C   r   r   )r	   log2r   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   r-   q   r   r-   c                 C   r   r   )r	   isinfr   r   r   r   r.   u   r   r.   c                 C   r   r   )r	   isfiniter   r   r   r   r/   y   r   r/   c                 C   r   r   )r	   hypotr   r   r   r   r   r0   }   r   r0   c                 C   r   r   )r	   	nextafterr1   r   r   r   r2      r   r2   c                 C   r   r   )r	   degreesr   r   r   r   r3      r   r3   c                 C   r   r   )r	   radiansr   r   r   r   r4      r   r4   c                 C   r   r   )r	   erfr   r   r   r   r5      r   r5   c                 C   r   r   )r	   erfcr   r   r   r   r6      r   r6   c                 C   r   r   )r	   gammar   r   r   r   r7      r   r7   c                 C   r   r   )r	   lgammar   r   r   r   r8      r   r8   c                 C   r   r   )r	   powr1   r   r   r   r9      r   r9   c                 C   r   r   )r	   gcdr1   r   r   r   r:      r   r:   c                 C   r   r   )r	   copysignr1   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   r@   c                   @   s  e Zd Zdd ZdaddZdad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ee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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 Z0dVdW Z1dXdY Z2dZd[ Z3d\d] Z4d^d_ Z5d`S )bTestMathLibc                 C   s   t t}| | |  d S r   )r   r@   assertPreciseEqual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   float32rB   )rD   pyfuncx_typesx_valuesrK   kwargsrE   txvxgotexpectedactual_precrL   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 )NrH   zfor inputs (%r, %r)rJ   rM   )rD   rP   rQ   rR   y_valuesrK   rE   tyr   r   rV   rW   rX   rL   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uint64rO   float64floatrY   rD   rP   rQ   rR   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rm         ro   皙?皙?)r
   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   test_sin      zTestMathLib.test_sinwin32z'not exactly equal on win32 (issue #597)c                 C   rj   rk   )r   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   test_cos   s   zTestMathLib.test_cosc                 C   rj   rk   )r   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   test_tan   rt   zTestMathLib.test_tanc                 C   rj   )Nro   rp   ro   ro   rp   ro   rq   rr   )r    r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   	test_sqrt   rt   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 )Nrx   rH   rK   )r"   r   r`   rc   rY   ra   rb   rd   re   rO   rf   rD   rP   rR   rQ   r   r   r   test_npy_sqrt   s   zTestMathLib.test_npy_sqrtc                 C   rj   rk   )r#   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   test_exp  rt   zTestMathLib.test_exp)      zneeds Python 3.11+c                 C   rj   rk   )r$   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   	test_exp2  s   zTestMathLib.test_exp2c                 C   rj   rk   )r%   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   
test_expm1  rt   zTestMathLib.test_expm1c                 C   rj   N)rp   
   d   i  i i@B rq   g?)r&   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   test_log  rt   zTestMathLib.test_logc                 C   rj   r   )r'   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   
test_log1p$  rt   zTestMathLib.test_log1pc                 C   rj   r   )r(   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   
test_log10,  rt   zTestMathLib.test_log10c                 C   rj   r   )r)   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   	test_log24  rt   zTestMathLib.test_log2c                 C   rj   Nrp   rp   rp   rp   rp   rp         ?r   )r   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   	test_asin<  rt   zTestMathLib.test_asinc                 C   rj   r   )r   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   	test_acosD  rt   zTestMathLib.test_acosc                 C   rj   rk   )r   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   	test_atanL  rt   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 )Nrl   c                 S      g | ]}|d  qS ro   r   .0r   r   r   r   
<listcomp>Z      z*TestMathLib.test_atan2.<locals>.<listcomp>)r   r   r`   ra   rb   rc   rd   re   rO   rf   r\   rD   rP   rQ   rR   rZ   r   r   r   
test_atan2T     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   doublerz   )r   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   
test_asinh]     zTestMathLib.test_asinhc                 C   rj   r   )r   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   
test_acoshe  rt   zTestMathLib.test_acoshc                 C   r   )Nr   r   r   r   r   r   rq   rq   r   rz   )r   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   
test_atanhm  r   zTestMathLib.test_atanhc                 C   rj   r   )r   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   	test_sinhu  rt   zTestMathLib.test_sinhc                 C   rj   r   )r   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   	test_cosh}  rt   zTestMathLib.test_coshc                 C   rj   )Nr   )r   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   	test_tanh  rt   zTestMathLib.test_tanhc                 C   rj   N)r   r   r   r   r   r   rq   gffffff?)r*   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   
test_floor  rt   zTestMathLib.test_floorc                 C   rj   r   )r+   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   	test_ceil  rt   zTestMathLib.test_ceilc                 C   rj   r   )r,   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   
test_trunc  rt   zTestMathLib.test_truncc                 C      |  t d S r   )ri   r-   rD   r   r   r   
test_isnan     zTestMathLib.test_isnanc                 C   r   r   )ri   r.   r   r   r   r   
test_isinf  r   zTestMathLib.test_isinfc                 C   r   r   )ri   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)rp   ro   r~            zG?(\?c                 S      g | ]}|d  qS r   r   r   r   r   r   r     r   z*TestMathLib.test_hypot.<locals>.<listcomp>rH   c                 S   s   t | |  ||  S r   r   r1   r   r   r   naive_hypot  s   z+TestMathLib.test_hypot.<locals>.naive_hypotg      >@rz   errorz overflow encountered in .*scalar)r0   r   rb   re   rO   rf   r\   r   r   as_dtypetyper!   finfomaxrB   
assertTruer/   warningscatch_warningssimplefilterRuntimeWarningassertRaisesRegex)rD   rP   rQ   rR   rZ   rK   r   rE   flttydtval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)r^   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   )r^               ?r~   )r2   r   rO   rf   ra   rb   rd   re   r\   r	   r]   )rD   rP   rQ   rR   	y1_values	y2_valuesr   r   r   test_nextafter  s   zTestMathLib.test_nextafterc                 C   rj   r   )r3   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   test_degrees  rt   zTestMathLib.test_degreesc                 C   rj   r   )r4   r   r`   ra   rb   rc   rd   re   rO   rf   rY   rh   r   r   r   test_radians  rt   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                r^   r   r   r]   ro   r   rK   ulps)r5   rg   r   rO   rf   lenrY   r{   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   r^   r   r   r]   ro   r   r   r   )r6   rg   r   rO   rf   r   rY   r{   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   ro   r   r~   r   皙rq         @g333333$@g      I@r]      )r7   r   rO   rf   r   rY   rg   r{   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   rq   g      i@g    _Bgꌠ9Y>)Fr]   ro   r   rz   )r8   rg   r   rO   rf   r   rY   r{   r   r   r   test_lgamma  s   zTestMathLib.test_lgammac                 C   r   )Nrl   c                 S   r   r   r   r   r   r   r   r     r   z(TestMathLib.test_pow.<locals>.<listcomp>)r9   r   r`   ra   rb   rc   rd   re   rO   rf   r\   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)rm   rn   r   rp   ro      r   ro   )r   rp   ro   r   	      )	itertoolsr   r   r   r:   sortedr   signed_domainunsigned_domainrN   r\   )
rD   r   r   r   rP   signed_argsunsigned_argsrQ   rR   rZ   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 )
Nrm   rn   r   r^   rp   ro   -infr]   r_   )
r;   r   rO   rf   rg   listrN   r   r   r\   )rD   rP   value_typesvaluesrQ   rR   rZ   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   r^   g      @r   r]   r_   rG   rz   )r<   r   rO   rf   rg   rY   rh   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   rm   )r   rp   )r^   r   )r^   rp   )r   r   )r   rp   r]   r   r   r_   rI   )r=   r   r   rO   rf   rg   rB   )rD   rP   rE   r   argsrL   r   r   r   
test_ldexp.  s   

zTestMathLib.test_ldexpN)rG   )6__name__
__module____qualname__rF   rY   r\   ri   rs   unittestskipIfsysplatformrv   rw   ry   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   r   r   r   r   r   r   r   r   rA      sd    


	


				rA   __main__)=r   r	   r   r   r   numpyr!   numbar   r   numba.tests.supportr   numba.npr   numba.core.utilsr   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   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r@   rA   r   mainr   r   r   r   <module>   sv       
