o
    8ήcFd                     @   s  d dl Zd dlmZmZmZ d dlmZ d dlm	Z	m
Z
mZmZmZmZmZ d dl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 Z0dEdF Z1dGdH Z2dIdJ Z3dKdL Z4dMdN Z5dOdP Z6dQdR Z7dSdT Z8G dUdV dVeZ9e:dWkre;  dS dS )X    N)unittestCUDATestCaseskip_on_cudasim)numpy_support)cudafloat32float64int32	vectorizevoidint64c                 C       t d}t| | ||< d S N   )r   gridmathacosABi r   H/tmp/pip-target-vg8gfxp4/lib/python/numba/cuda/tests/cudapy/test_math.py	math_acos      
r   c                 C   r   r   )r   r   r   asinr   r   r   r   	math_asin   r   r   c                 C   r   r   )r   r   r   atanr   r   r   r   	math_atan   r   r   c                 C   r   r   )r   r   r   acoshr   r   r   r   
math_acosh   r   r    c                 C   r   r   )r   r   r   asinhr   r   r   r   
math_asinh   r   r"   c                 C   r   r   )r   r   r   atanhr   r   r   r   
math_atanh!   r   r$   c                 C   r   r   )r   r   r   cosr   r   r   r   math_cos&   r   r&   c                 C   r   r   )r   r   r   sinr   r   r   r   math_sin+   r   r(   c                 C   r   r   )r   r   r   tanr   r   r   r   math_tan0   r   r*   c                 C   r   r   )r   r   r   coshr   r   r   r   	math_cosh5   r   r,   c                 C   r   r   )r   r   r   sinhr   r   r   r   	math_sinh:   r   r.   c                 C   r   r   )r   r   r   tanhr   r   r   r   	math_tanh?   r   r0   c                 C   &   t d}t| | || ||< d S r   )r   r   r   atan2r   r   Cr   r   r   r   
math_atan2D      
r5   c                 C   r   r   )r   r   r   expr   r   r   r   math_expI   r   r8   c                 C   r   r   )r   r   r   erfr   r   r   r   math_erfN   r   r:   c                 C   r   r   )r   r   r   erfcr   r   r   r   	math_erfcS   r   r<   c                 C   r   r   )r   r   r   expm1r   r   r   r   
math_expm1X   r   r>   c                 C   r   r   )r   r   r   fabsr   r   r   r   	math_fabs]   r   r@   c                 C   r   r   )r   r   r   gammar   r   r   r   
math_gammab   r   rB   c                 C   r   r   )r   r   r   lgammar   r   r   r   math_lgammag   r   rD   c                 C   r   r   )r   r   r   logr   r   r   r   math_logl   r   rF   c                 C   r   r   )r   r   r   log2r   r   r   r   	math_log2q   r   rH   c                 C   r   r   )r   r   r   log10r   r   r   r   
math_log10v   r   rJ   c                 C   r   r   )r   r   r   log1pr   r   r   r   
math_log1p{   r   rL   c                 C   r1   r   )r   r   r   	remainderr3   r   r   r   math_remainder   r6   rN   c                 C   r   r   )r   r   r   sqrtr   r   r   r   	math_sqrt   r   rP   c                 C   r1   r   )r   r   r   hypotr3   r   r   r   
math_hypot   r6   rR   c                 C   r1   r   )r   r   r   powr3   r   r   r   math_pow   r6   rT   c                 C   r   r   )r   r   r   ceilr   r   r   r   	math_ceil   r   rV   c                 C   r   r   )r   r   r   floorr   r   r   r   
math_floor   r   rX   c                 C   r1   r   )r   r   r   copysignr3   r   r   r   math_copysign   r6   rZ   c                 C   r1   r   )r   r   r   fmodr3   r   r   r   	math_fmod   r6   r\   c                 C   s(   t d}t| | \||< ||< d S r   )r   r   r   modfr3   r   r   r   	math_modf   s   
r^   c                 C   r   r   )r   r   r   isnanr   r   r   r   
math_isnan   r   r`   c                 C   r   r   )r   r   r   isinfr   r   r   r   
math_isinf   r   rb   c                 C   r   r   )r   r   r   isfiniter   r   r   r   math_isfinite   r   rd   c                 C   r   r   )r   r   r   degreesr   r   r   r   math_degrees   r   rf   c                 C   r   r   )r   r   r   radiansr   r   r   r   math_radians   r   rh   c                 C   s"   t d}| | ||  ||< d S r   r   r   r3   r   r   r   math_pow_binop      
rj   c                 C   s"   t d}| | ||  ||< d S r   ri   r3   r   r   r   math_mod_binop   rk   rl   c                   @   s  e Zd ZdddZdddZddd	Zdd
dZdd Zdd Zdd Z	dd Z
dddZdddZdddZdddZdd Zddd Zdd!d"Zdd#d$Zdd%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 Z%dKdL Z&dMdN Z'dOdP Z(dQdR Z)dSdT Z*dUdV Z+dWdX Z,dYdZ Z-e.d[d\d] Z/d^d_ Z0d`da Z1dbdc Z2ddde Z3dfdg Z4dhdi Z5djdk Z6dldm Z7dndo Z8dpdq Z9drds Z:dtdu Z;dvdw Z<dxdy Z=dzd{ Z>d|d} Z?d~S )TestCudaMathr   r   c                 C      |  ||tjtj|| d S Nunary_templatenpr   selffuncnpfuncstartstopr   r   r   unary_template_float32      z#TestCudaMath.unary_template_float32c                 C   rn   ro   rq   rr   r   rs   r   r   r   unary_template_float64   rz   z#TestCudaMath.unary_template_float642   c                 C      |  ||tjtj|| d S ro   )rq   rr   r   r   rs   r   r   r   unary_template_int64   rz   z!TestCudaMath.unary_template_int64c                 C   r~   ro   )rq   rr   uint64r   rs   r   r   r   unary_template_uint64   rz   z"TestCudaMath.unary_template_uint64c                 C   s   d}t ||||}t ||}	t|d d d }
t|d d d }t|
|f|}|d|f ||	 |t jkrBd}nd}t j	j
|||	|d d S )Nr}   r   gvIh%<=ư>rtol)rr   linspaceastype
empty_liker   
from_dtyper   jitr   testingassert_allclose)rt   ru   rv   npdtype	nprestyperw   rx   nelemr   r   arytyperestypecfuncr   r   r   r   rq      s   
zTestCudaMath.unary_templatec           
   	   C   s   t |}|jd }t jd||jdd|jt jt jg|d}t j|t jd}t	
|d d d td d d f|}	|	d|jf || t j||| |	d|jf | | t j|||  d S )N   g        g      ?g      ?dtyper   )rr   finfotinyarraymaxinfnanr   r	   r   r   sizer   assert_array_equal)
rt   ru   rv   r   npmtypefidenormr   r   r   r   r   r   unary_bool_special_values   s   

&z&TestCudaMath.unary_bool_special_valuesc                 C      |  ||tjt d S ro   )r   rr   r   rt   ru   rv   r   r   r   !unary_bool_special_values_float32      z.TestCudaMath.unary_bool_special_values_float32c                 C   r   ro   )r   rr   r   r   r   r   r   !unary_bool_special_values_float64  r   z.TestCudaMath.unary_bool_special_values_float64c                 C   rn   ro   rp   rs   r   r   r   unary_bool_template_float32  rz   z(TestCudaMath.unary_bool_template_float32c                 C   rn   ro   r{   rs   r   r   r   unary_bool_template_float64  rz   z(TestCudaMath.unary_bool_template_float641   c                 C   rn   ro   )rq   rr   r	   rs   r   r   r   unary_bool_template_int32
  rz   z&TestCudaMath.unary_bool_template_int32c                 C   rn   ro   )rq   rr   r   rs   r   r   r   unary_bool_template_int64  rz   z&TestCudaMath.unary_bool_template_int64c                 C   s   d}t ||||}t j|jt jd}	|d d d }
td d d }t|
|f|}|d|f ||	 t j	|||	 d S )Nr}   r   r   )
rr   r   r   emptyshaper	   r   r   r   r   )rt   ru   rv   r   r   rw   rx   r   r   r   iarytypeoarytyper   r   r   r   unary_bool_template  s   z TestCudaMath.unary_bool_templatec                 C   rn   ro   )binary_templaterr   r   rs   r   r   r   binary_template_float32  rz   z$TestCudaMath.binary_template_float32c                 C   rn   ro   )r   rr   r   rs   r   r   r   binary_template_float64  rz   z$TestCudaMath.binary_template_float64c                 C   r~   ro   )r   rr   r   r   rs   r   r   r   binary_template_int64   rz   z"TestCudaMath.binary_template_int64c                 C   r~   ro   )r   rr   r   r   rs   r   r   r   binary_template_uint64#  rz   z#TestCudaMath.binary_template_uint64c                 C   s   d}t ||||}t ||}	t|d d d }
t|d d d }t|
|
|f|}|  |d|f |||	 t j	
||||	 d S )Nr}   r   )rr   r   r   r   r   r   r   r   bindr   r   )rt   ru   rv   r   r   rw   rx   r   r   r   r   r   r   r   r   r   r   &  s   zTestCudaMath.binary_templatec                 C   H   |  ttj | ttj | jttjddd | jttjddd d S Nr   rw   rx   )ry   r   rr   arccosr|   r   r   rt   r   r   r   test_math_acos4     zTestCudaMath.test_math_acosc                 C   r   r   )ry   r   rr   arcsinr|   r   r   r   r   r   r   test_math_asin?  r   zTestCudaMath.test_math_asinc                 C   <   |  ttj | ttj | ttj | ttj d S ro   )ry   r   rr   arctanr|   r   r   r   r   r   r   test_math_atanJ     zTestCudaMath.test_math_atanc                 C   T   | j ttjddd | jttjddd | jttjddd | jttjddd d S )Nr      r   )ry   r    rr   arccoshr|   r   r   r   r   r   r   test_math_acoshS     zTestCudaMath.test_math_acoshc                 C   r   ro   )ry   r"   rr   arcsinhr|   r   r   r   r   r   r   test_math_asinh\  r   zTestCudaMath.test_math_asinhc                 C   r   )Nr   g?r   )ry   r$   rr   arctanhr|   r   r   r   r   r   r   test_math_atanhe  r   zTestCudaMath.test_math_atanhc                 C   r   ro   )ry   r&   rr   r%   r|   r   r   r   r   r   r   test_math_cosn  r   zTestCudaMath.test_math_cosc                 C   r   ro   )ry   r(   rr   r'   r|   r   r   r   r   r   r   test_math_sinw  r   zTestCudaMath.test_math_sinc                 C   r   ro   )ry   r*   rr   r)   r|   r   r   r   r   r   r   test_math_tan  r   zTestCudaMath.test_math_tanc                 C   r   ro   )ry   r,   rr   r+   r|   r   r   r   r   r   r   test_math_cosh  r   zTestCudaMath.test_math_coshc                 C   r   ro   )ry   r.   rr   r-   r|   r   r   r   r   r   r   test_math_sinh  r   zTestCudaMath.test_math_sinhc                 C   r   ro   )ry   r0   rr   r/   r|   r   r   r   r   r   r   test_math_tanh  r   zTestCudaMath.test_math_tanhc                 C   r   ro   )r   r5   rr   arctan2r   r   r   r   r   r   r   test_math_atan2  r   zTestCudaMath.test_math_atan2c                 C   @   t dd }| t| | t| | t| | t| d S )Nc                 S   
   t | S ro   )r   r9   xr   r   r   ufunc     
z)TestCudaMath.test_math_erf.<locals>.ufunc)r
   ry   r:   r|   r   r   rt   r   r   r   r   test_math_erf     
zTestCudaMath.test_math_erfc                 C   r   )Nc                 S   r   ro   )r   r;   r   r   r   r   r     r   z*TestCudaMath.test_math_erfc.<locals>.ufunc)r
   ry   r<   r|   r   r   r   r   r   r   test_math_erfc  r   zTestCudaMath.test_math_erfcc                 C   r   ro   )ry   r8   rr   r7   r|   r   r   r   r   r   r   test_math_exp  r   zTestCudaMath.test_math_expc                 C   r   ro   )ry   r>   rr   r=   r|   r   r   r   r   r   r   test_math_expm1  r   zTestCudaMath.test_math_expm1c                 C   L   | j ttjdd | jttjdd | jttjdd | jttjdd d S Nrw   )ry   r@   rr   r?   r|   r   r   r   r   r   r   test_math_fabs     zTestCudaMath.test_math_fabsc                 C   P   t dd }| jt|dd | jt|dd | jt|dd | jt|dd d S )Nc                 S   r   ro   )r   rA   r   r   r   r   r     r   z+TestCudaMath.test_math_gamma.<locals>.ufunc皙?r   r   )r
   ry   rB   r|   r   r   r   r   r   r   test_math_gamma     
zTestCudaMath.test_math_gammac                 C   r   )Nc                 S   r   ro   )r   rC   r   r   r   r   r     r   z,TestCudaMath.test_math_lgamma.<locals>.ufuncr   r   r   )r
   ry   rD   r|   r   r   r   r   r   r   test_math_lgamma  r   zTestCudaMath.test_math_lgammac                 C   r   Nr   r   )ry   rF   rr   rE   r|   r   r   r   r   r   r   test_math_log  r   zTestCudaMath.test_math_logc                 C   r   r   )ry   rH   rr   rG   r|   r   r   r   r   r   r   test_math_log2  r   zTestCudaMath.test_math_log2c                 C   r   r   )ry   rJ   rr   rI   r|   r   r   r   r   r   r   test_math_log10
  r   zTestCudaMath.test_math_log10c                 C   r   ro   )ry   rL   rr   rK   r|   r   r   r   r   r   r   test_math_log1p  r   zTestCudaMath.test_math_log1pc                 C   sL   | j ttjdd | jttjdd | jttjdd | jttjdd d S )Ngdy=r   r   )r   rN   rr   rM   r   r   r   r   r   r   r   test_math_remainder  r   z TestCudaMath.test_math_remainderz3math.remainder(0, 0) raises a ValueError on CUDASimc                 C   sZ   t ttd d d ttdd }tdtj}|d |dd | t|d  d S )Nr   c                 S   s   t ||| d< d S )Nr   )r   rM   )rr   yr   r   r   test_0_0$  s   z6TestCudaMath.test_math_remainder_0_0.<locals>.test_0_0)r   r   r   )	r   r   r   r   r   rr   zeros
assertTruer_   )rt   r   r   r   r   r   test_math_remainder_0_0"  s
   
z$TestCudaMath.test_math_remainder_0_0c                 C   r   ro   )ry   rP   rr   rO   r|   r   r   r   r   r   r   test_math_sqrt.  r   zTestCudaMath.test_math_sqrtc                 C   r   ro   )r   rR   rr   rQ   r   r   r   r   r   r   r   test_math_hypot7  r   zTestCudaMath.test_math_hypotc           
      C   s   d}t dd||}t j|t jd}t |}t|d d d }t	|td d d |ft
}|  |d|f ||| t |}tt|D ]}	t||	 ||	 ||	< qKt jjt ||||dd d S )Nr}   r      r   r   r   r   )rr   r   r   aranger	   r   r   r   r   r   rT   r   rangelenr   rS   r   r   power)
rt   r   r   r   r   r4   r   r   Crefr   r   r   r   pow_template_int32@  s   

$zTestCudaMath.pow_template_int32c                 C   s8   |  ttj | ttj | tj | tj d S ro   )r   rT   rr   r   r   r   r   r   r   r   r   r   test_math_powR  s   zTestCudaMath.test_math_powc                 C       |  ttj | ttj d S ro   )r   rj   rr   r   r   r   r   r   r   test_math_pow_binop[     z TestCudaMath.test_math_pow_binopc                 C   r   ro   )ry   rV   rr   rU   r|   r   r   r   r   r   r   test_math_ceilb  r   zTestCudaMath.test_math_ceilc                 C   r   ro   )ry   rX   rr   rW   r|   r   r   r   r   r   r   test_math_floork  r   zTestCudaMath.test_math_floorc                 C   (   | j ttjdd | jttjdd d S r   )r   rZ   rr   rY   r   r   r   r   r   test_math_copysignt     zTestCudaMath.test_math_copysignc                    s   fdd} fdd}d}  d |tdd|tjtd d  d	 W d    n1 s/w   Y    d
 |ttjtj gtjtd d  d	 W d    n1 sXw   Y    d |tjtd d  d	 W d    n1 sxw   Y    d |tdd|tjtd d  d	 W d    n1 sw   Y    d |ttjtj gtjtd d  d	 W d    n1 sw   Y    d |tjtd d  d	 W d    d S 1 sw   Y  d S )Nc                    sv   t jt jg| d}t |}t |}t|||ft}|dt|f |||  t 	|  t 	| d S )Nr   r   )
rr   r   r   
zeros_liker   r   r^   r   r   r_   )r   r   r   r   r4   r   r   r   r   modf_template_nan|  s   

z6TestCudaMath.test_math_modf.<locals>.modf_template_nanc                    s   |  |} t| }t| }t|||ft}|dt| f | || t| \}} t	||  t	|| d S r   )
r   rr   r	  r   r   r^   r   r]   r   array_equal)r   r   r   r   r4   r   DEr   r   r   modf_template_compare  s   


z:TestCudaMath.test_math_modf.<locals>.modf_template_comparer}   zfloat32 modf on simple floatr   
   )r   r   zfloat32 modf on +- infinityzfloat32 modf on nanzfloat64 modf on simple floatzfloat64 modf on +- infinityzfloat64 modf on nan)subTestrr   r   r   r   r   r   )rt   r
  r  r   r   r   r   test_math_modf{  s:   	




"zTestCudaMath.test_math_modfc                 C   r  r   )r   r\   rr   r[   r   r   r   r   r   test_math_fmod  r  zTestCudaMath.test_math_fmodc                 C   r  r   )r   rl   rr   r[   r   r   r   r   r   test_math_mod_binop  r  z TestCudaMath.test_math_mod_binopc                 C   X   |  ttj | ttj | ttj | ttj | ttj | ttj d S ro   )	r   r`   rr   r_   r   r   r   r   r   r   r   r   r   test_math_isnan     zTestCudaMath.test_math_isnanc                 C   r  ro   )	r   rb   rr   ra   r   r   r   r   r   r   r   r   r   test_math_isinf  r  zTestCudaMath.test_math_isinfc                 C   r  ro   )	r   rd   rr   rc   r   r   r   r   r   r   r   r   r   test_math_isfinite  r  zTestCudaMath.test_math_isfinitec                 C   r  ro   )r   rf   rr   re   r   r   r   r   r   test_math_degrees  r  zTestCudaMath.test_math_degreesc                 C   r  ro   )r   rh   rr   rg   r   r   r   r   r   test_math_radians  r  zTestCudaMath.test_math_radiansN)r   r   )r   r}   )r   r   )@__name__
__module____qualname__ry   r|   r   r   rq   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   rm      s|    












																		
					,rm   __main__)<numpyrr   numba.cuda.testingr   r   r   numba.npr   numbar   r   r   r	   r
   r   r   r   r   r   r   r    r"   r$   r&   r(   r*   r,   r.   r0   r5   r8   r:   r<   r>   r@   rB   rD   rF   rH   rJ   rL   rN   rP   rR   rT   rV   rX   rZ   r\   r^   r`   rb   rd   rf   rh   rj   rl   rm   r  mainr   r   r   r   <module>   sj    $    