U
    hâËdP8  ã                   @   sº  d dl Z d dlZd dlmZ d dlmZmZmZmZ d dl	m
Z
 d dlmZmZmZmZ d dlmZ d dlmZ e
ƒ ZejZg Zedd	e jfg7 Zed
de jfg7 Zedde jfg7 Zg Zedde jfg7 Zedde jfg7 Zedde jfg7 Zedde jfg7 Zedde jfg7 Zedde j fg7 Zedde j!fg7 Zedde j"fg7 Zedde j#fg7 Zed d!e j$fg7 Zed"d#e j%fg7 Zed$d%e j&fg7 Zed&d'e j'fg7 Zed(d)e j(fg7 Zed*d+e j)fg7 Zed,d-e j*fg7 Zed.d/e j+fg7 Zed0d1e j,fg7 Zed2d3e j-fg7 Zed4d5e j.fg7 Zed6d7e j/fg7 Zed8d9e j0fg7 Zed:d;e j1fg7 Zed<d=e j2fg7 Zed>d?e j3fg7 Zed@dAe j4fg7 Zi Z5dBe5d/< dCe5d7< dDe5d?< dEe5d< dFe5d%< dGe5d'< dHe5d#< g Z6e6dIdJe j7fg7 Z6e6dKdLe j8fg7 Z6e6dMdNe j9fg7 Z6e6dOdPe j:fg7 Z6e6dQdRe j;fg7 Z6e6dSdTe j<fg7 Z6i Z=dUe=dN< ee jej>ƒee jej>ƒdVdW„ ƒƒZ?eej@ejejƒdXdY„ ƒZAee jej>ƒdZd[„ ƒZBee j/ejCƒd\d]„ ƒZDee j+ejCƒd^d_„ ƒZEee j%ejCƒd`da„ ƒZFee j'ejCƒdbdc„ ƒZGee j&ejCƒddde„ ƒZHee jejCƒdfdg„ ƒZIee jejCƒdhdi„ ƒZJee jejCƒdjdk„ ƒZKee j$ejCƒdldm„ ƒZLee jejCƒdndo„ ƒZMee j4ejCƒdpdq„ ƒZNdrds„ ZOdtdu„ ZPdvdw„ ZQdxdy„ ZRdzd{„ ZSd|d}„ ZTd~d„ ZUd€d�„ ZVd‚dƒ„ ZWeD ]8\ZXZYZZe[eeYƒZ\e[eeXƒZ]eOeZee\ƒ eOeZee]ƒ �qØeD ]P\ZXZYZZe[eeYƒZ\e[eeXƒZ]eReZee\ƒ eReZee]ƒ eSeZee]ƒ eSeZee]ƒ �qe6D ]P\ZXZYZZe[eeYƒZ\e[eeXƒZ]eVeZee\ƒ eVeZee]ƒ eWeZee]ƒ eWeZee]ƒ �qld„d…„ Z^e^ejej_ƒ e^ejej`ƒ d†d‡„ Zaeaejejbƒ eaejejcƒ dˆd‰„ Zdedejejeƒ edejejfƒ dŠd‹„ Zgegejejhƒ egejejiƒ dŒd�„ Zjejejejkƒ ejejejlƒ eSe jleejlƒ eSe jleejlƒ dŽd�„ Zmemejejnƒ emejejoƒ dS )�é    N)Úir)ÚtypesÚtypingÚcgutilsÚtargetconfig)ÚRegistry)Úfloat32Úfloat64Úint64Úuint64)Ú	libdevice)ÚcudaZisnandZisnanfZisinfdZisinffZ	isfinitedZfinitefÚceilZceilfÚfloorZfloorfÚfabsZfabsfÚexpZexpfÚexpm1Zexpm1fÚerfZerffÚerfcZerfcfZtgammaZtgammafÚlgammaZlgammafÚsqrtZsqrtfÚlogZlogfÚlog2Zlog2fÚlog10Zlog10fÚlog1pZlog1pfÚacoshZacoshfÚacosZacosfÚcosZcosfÚcoshZcoshfÚasinhZasinhfÚasinZasinfÚsinZsinfÚsinhZsinhfÚatanZatanfÚatanhZatanhfÚtanZtanfÚtruncZtruncfZ	fast_cosfZ	fast_sinfZ	fast_tanfZ	fast_expfZ
fast_log2fZfast_log10fZ	fast_logfÚcopysignZ	copysignfÚatan2Zatan2fÚpowZpowfÚfmodZfmodfÚhypotZhypotfÚ	remainderZ
remainderfZ	fast_powfc                 C   s   |   tjd¡S )Nr   ©Zget_constantr   Úboolean©ÚcontextÚbuilderÚsigÚargs© r4   úL/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/cuda/mathimpl.pyÚmath_isinf_isnan_intD   s    r6   c              	   C   sh   | j r,t ttt¡}|  tj|¡}|||ƒS t ||d ¡� | j	 
|d¡ W 5 Q R X |j|Ž }|S d S )Né   )zdivision by zero)Úfastmathr   Ú	signaturer   Úget_functionr   Zfast_fdividefr   Zif_zeroZerror_modelZfp_zero_divisionZfdiv)r0   r1   r2   r3   ÚimplÚresr4   r4   r5   Úmaybe_fast_truedivJ   s    

r=   c                 C   s   |   tjd¡S )Nr7   r-   r/   r4   r4   r5   Úmath_isfinite_intW   s    r>   c                 C   s   dd„ }|   ||||¡S )Nc                 S   s   t j | ¡S ©N)r   Úfp16Zhsin©Úxr4   r4   r5   Úfp16_sin^   s    zfp16_sin_impl.<locals>.fp16_sin©Zcompile_internal)r0   r1   r2   r3   rC   r4   r4   r5   Úfp16_sin_impl\   s    rE   c                 C   s   dd„ }|   ||||¡S )Nc                 S   s   t j | ¡S r?   )r   r@   ZhcosrA   r4   r4   r5   Úfp16_cosf   s    zfp16_cos_impl.<locals>.fp16_cosrD   )r0   r1   r2   r3   rF   r4   r4   r5   Úfp16_cos_impld   s    rG   c                 C   s   dd„ }|   ||||¡S )Nc                 S   s   t j | ¡S r?   )r   r@   ZhlogrA   r4   r4   r5   Úfp16_logn   s    zfp16_log_impl.<locals>.fp16_logrD   )r0   r1   r2   r3   rH   r4   r4   r5   Úfp16_log_impll   s    rI   c                 C   s   dd„ }|   ||||¡S )Nc                 S   s   t j | ¡S r?   )r   r@   Zhlog10rA   r4   r4   r5   Ú
fp16_log10v   s    z#fp16_log10_impl.<locals>.fp16_log10rD   )r0   r1   r2   r3   rJ   r4   r4   r5   Úfp16_log10_implt   s    rK   c                 C   s   dd„ }|   ||||¡S )Nc                 S   s   t j | ¡S r?   )r   r@   Zhlog2rA   r4   r4   r5   Ú	fp16_log2~   s    z!fp16_log2_impl.<locals>.fp16_log2rD   )r0   r1   r2   r3   rL   r4   r4   r5   Úfp16_log2_impl|   s    rM   c                 C   s   dd„ }|   ||||¡S )Nc                 S   s   t j | ¡S r?   )r   r@   ZhexprA   r4   r4   r5   Úfp16_exp†   s    zfp16_exp_impl.<locals>.fp16_exprD   )r0   r1   r2   r3   rN   r4   r4   r5   Úfp16_exp_impl„   s    rO   c                 C   s   dd„ }|   ||||¡S )Nc                 S   s   t j | ¡S r?   )r   r@   ZhfloorrA   r4   r4   r5   Ú
fp16_floorŽ   s    z#fp16_floor_impl.<locals>.fp16_floorrD   )r0   r1   r2   r3   rP   r4   r4   r5   Úfp16_floor_implŒ   s    rQ   c                 C   s   dd„ }|   ||||¡S )Nc                 S   s   t j | ¡S r?   )r   r@   ZhceilrA   r4   r4   r5   Ú	fp16_ceil–   s    z!fp16_ceil_impl.<locals>.fp16_ceilrD   )r0   r1   r2   r3   rR   r4   r4   r5   Úfp16_ceil_impl”   s    rS   c                 C   s   dd„ }|   ||||¡S )Nc                 S   s   t j | ¡S r?   )r   r@   ZhsqrtrA   r4   r4   r5   Ú	fp16_sqrtž   s    z!fp16_sqrt_impl.<locals>.fp16_sqrtrD   )r0   r1   r2   r3   rT   r4   r4   r5   Úfp16_sqrt_implœ   s    rU   c                 C   s   dd„ }|   ||||¡S )Nc                 S   s   t j | ¡S r?   )r   r@   ZhabsrA   r4   r4   r5   Ú	fp16_fabs¦   s    z!fp16_fabs_impl.<locals>.fp16_fabsrD   )r0   r1   r2   r3   rV   r4   r4   r5   Úfp16_fabs_impl¤   s    rW   c                 C   s   dd„ }|   ||||¡S )Nc                 S   s   t j | ¡S r?   )r   r@   ZhtruncrA   r4   r4   r5   Ú
fp16_trunc®   s    z#fp16_trunc_impl.<locals>.fp16_truncrD   )r0   r1   r2   r3   rX   r4   r4   r5   Úfp16_trunc_impl¬   s    rY   c                    s    ‡ ‡fdd„}t | ˆƒ|ƒ d S )Nc                    s4   |   ˆ t tjˆ¡¡}|||ƒ}|  ||tjtj¡S r?   )r:   r   r9   r   Úint32Úcastr.   )r0   r1   r2   r3   Úlibfunc_implÚresult©ÚlibfuncÚtyr4   r5   Úlower_boolean_implµ   s
    ÿ
z(impl_boolean.<locals>.lower_boolean_impl©Úlower)Úkeyr`   r_   ra   r4   r^   r5   Úimpl_boolean´   s    re   c                    s   ‡ ‡fdd„}|S )Nc                    sR   ˆ }d }ˆt kr"| jr"t ˆ j¡}|d k	r4tt|ƒ}|  |t 	ˆˆ¡¡}|||ƒS r?   )
r   r8   Úunarys_fastmathÚgetÚ__name__Úgetattrr   r:   r   r9   ©r0   r1   r2   r3   Zactual_libfuncZfast_replacementr\   r^   r4   r5   Úlower_unary_impl¿   s    

ÿz.get_lower_unary_impl.<locals>.lower_unary_implr4   ©rd   r`   r_   rk   r4   r^   r5   Úget_lower_unary_impl¾   s    rm   c                 C   sz   ddt jf}t|g D ]H\}}}| |kr|tkr<tt|ƒ}n|tkrNtt|ƒ}t|||ƒ  S qtd| › d|› d�ƒ‚d S )NÚtanhÚtanhfúImplementation of ú for ú
 not found)	Úmathrn   Úunarysr   ri   r   r	   rm   ÚRuntimeError)Úfnr`   Z
tanh_implsÚfname64Úfname32rd   r;   r4   r4   r5   Úget_unary_impl_for_fn_and_tyÎ   s    
ry   c                 C   s   t | ||ƒ}t| |ƒ|ƒ d S r?   )rm   rc   rl   r4   r4   r5   Ú
impl_unaryà   s    rz   c                    s   ‡ fdd„}t | |ƒ|ƒ d S )Nc                    sn   |j d tkr|j}n"|j d tkr,|j}nd}t|ƒ‚||d t ¡ ƒ}t 	t
t
¡}|  ˆ |¡}|||gƒS )Nr   z<Only 64-bit integers are supported for generic unary int ops)r3   r
   Úsitofpr   ÚuitofpÚ	TypeErrorr   Ú
DoubleTyper   r9   r	   r:   )r0   r1   r2   r3   ÚconvertÚmÚargr\   ©r_   r4   r5   Úlower_unary_int_implæ   s    z,impl_unary_int.<locals>.lower_unary_int_implrb   )rd   r`   r_   rƒ   r4   r‚   r5   Úimpl_unary_intå   s    r„   c                    s   ‡ ‡fdd„}|S )Nc                    sT   ˆ }d }ˆt kr"| jr"t ˆ j¡}|d k	r4tt|ƒ}|  |t 	ˆˆˆ¡¡}|||ƒS r?   )
r   r8   Úbinarys_fastmathrg   rh   ri   r   r:   r   r9   rj   r^   r4   r5   Úlower_binary_implø   s    
ÿz0get_lower_binary_impl.<locals>.lower_binary_implr4   ©rd   r`   r_   r†   r4   r^   r5   Úget_lower_binary_impl÷   s    rˆ   c                 C   sh   t D ]H\}}}| |kr|tkr*tt|ƒ}n|tkr<tt|ƒ}t|||ƒ  S qtd| › d|› d�ƒ‚d S )Nrp   rq   rr   )Úbinarysr   ri   r   r	   rˆ   ru   )rv   r`   rw   rx   rd   r;   r4   r4   r5   Úget_binary_impl_for_fn_and_ty  s    
rŠ   c                 C   s    t | ||ƒ}t| ||ƒ|ƒ d S r?   )rˆ   rc   r‡   r4   r4   r5   Úimpl_binary  s    r‹   c                    s    ‡ fdd„}t | ||ƒ|ƒ d S )Nc                    sn   |j d tkr|j‰ n"|j d tkr,|j‰ nd}t|ƒ‚‡ fdd„|D ƒ}t ttt¡}|  	ˆ|¡}|||ƒS )Nr   z=Only 64-bit integers are supported for generic binary int opsc                    s   g | ]}ˆ |t  ¡ ƒ‘qS r4   )r   r~   )Ú.0r�   ©r   r4   r5   Ú
<listcomp>#  s     zBimpl_binary_int.<locals>.lower_binary_int_impl.<locals>.<listcomp>)
r3   r
   r{   r   r|   r}   r   r9   r	   r:   )r0   r1   r2   r3   r€   r\   r‚   r�   r5   Úlower_binary_int_impl  s    z.impl_binary_int.<locals>.lower_binary_int_implrb   )rd   r`   r_   r�   r4   r‚   r5   Úimpl_binary_int  s    r�   c                    s&   ‡ ‡fdd„}t tjˆtjƒ|ƒ d S )Nc                    s&   t  ˆˆtj¡}|  ˆ |¡}|||ƒS r?   ©r   r9   r   rZ   r:   )r0   r1   r2   r3   Zpowi_sigr\   r^   r4   r5   Úlower_pow_impl_intE  s    z(impl_pow_int.<locals>.lower_pow_impl_int)rc   rs   r)   r   rZ   )r`   r_   r’   r4   r^   r5   Úimpl_pow_intD  s    r“   c                    s0   t  ˆd¡‰‡ ‡‡fdd„}ttjˆƒ|ƒ d S )Né   c                    s"   t  ˆˆ¡}|  ˆ |¡}|||ƒS r?   ©r   r9   r:   )r0   r1   r2   r3   Zmodf_sigr\   ©r_   Zrettyr`   r4   r5   Úlower_modf_implT  s    z"impl_modf.<locals>.lower_modf_impl)r   ZUniTuplerc   rs   Úmodf)r`   r_   r—   r4   r–   r5   Ú	impl_modfQ  s    r™   c                    s4   t  ˆt jf¡‰‡ ‡‡fdd„}ttjˆƒ|ƒ d S )Nc                    s"   t  ˆˆ¡}|  ˆ |¡}|||ƒS r?   r•   )r0   r1   r2   r3   Z	frexp_sigr\   r–   r4   r5   Úlower_frexp_implc  s    z$impl_frexp.<locals>.lower_frexp_impl)r   ÚTuplerZ   rc   rs   Úfrexp)r`   r_   rš   r4   r–   r5   Ú
impl_frexp`  s    r�   c                    s&   ‡ ‡fdd„}t tjˆtjƒ|ƒ d S )Nc                    s&   t  ˆˆtj¡}|  ˆ |¡}|||ƒS r?   r‘   )r0   r1   r2   r3   Z	ldexp_sigr\   r^   r4   r5   Úlower_ldexp_implp  s    z$impl_ldexp.<locals>.lower_ldexp_impl)rc   rs   Úldexpr   rZ   )r`   r_   rž   r4   r^   r5   Ú
impl_ldexpo  s    r    c                    s"   ‡ ‡fdd„}t tjˆƒ|ƒ d S )Nc                    sR   dd„ }‡ ‡‡‡‡fdd„}‡ ‡fdd„}ˆt krLˆjrL|ƒ }|dkrL|ƒ S |ƒ S )Nc                  S   s   t  ¡  ¡ } | jS r?   )r   ZConfigStackÚtopZcompute_capability)Úflagsr4   r4   r5   Úget_compute_capability~  s    zBimpl_tanh.<locals>.lower_tanh_impl.<locals>.get_compute_capabilityc                     s"   t  ˆˆ¡} ˆ ˆ| ¡}|ˆˆ ƒS r?   r•   )Ztanh_sigr\   )r3   r1   r0   r_   r`   r4   r5   Útanh_impl_libdevice‚  s    z?impl_tanh.<locals>.lower_tanh_impl.<locals>.tanh_impl_libdevicec                     s0   t  t  ¡ t  ¡ g¡} t  | dd¡}ˆ |ˆ ¡S )Nztanh.approx.f32 $0, $1;z=f,f)r   ÚFunctionTypeZ	FloatTypeZ	InlineAsmÚcall)ZfntyÚasm)r3   r1   r4   r5   Útanhf_impl_fastmath‡  s    z?impl_tanh.<locals>.lower_tanh_impl.<locals>.tanhf_impl_fastmath)é   é   )r   r8   )r0   r1   r2   r3   r£   r¤   r¨   Úccr^   )r3   r1   r0   r5   Úlower_tanh_impl}  s    z"impl_tanh.<locals>.lower_tanh_impl)rc   rs   rn   )r`   r_   r¬   r4   r^   r5   Ú	impl_tanh|  s    r­   c                    sF   ‡ ‡fdd„}t tjˆ ˆ ƒ|ƒ t tjˆ ˆ ƒ|ƒ t tˆ ˆ ƒ|ƒ d S )Nc                    s   ‡ ‡fdd„}|   ||||¡S )Nc                    sî   |j ˆdƒkr,|jˆdƒkr,ˆ dƒˆ dƒ S | j ˆdƒkrX|j ˆdƒkrXˆ dƒˆ dƒ S t | j | j¡}t ||j ¡}t | j| j ¡}||j  }|jˆdƒkrÆ|t ||j ¡ }||jt |¡ 7 }|ˆ t |¡ƒˆ t 	|¡ˆ dƒ ƒ  S )Ng        g      ð?y                y              ð?)
ÚrealÚimagrs   r+   r)   r(   r   r   r   r!   )ÚaÚbZvabsÚlenÚatZphase©ÚctyÚftyr4   r5   Úcpow_internal¦  s    
ÿz3cpow_implement.<locals>.core.<locals>.cpow_internalrD   )r0   r1   r2   r3   r·   r´   r4   r5   Úcore¥  s    zcpow_implement.<locals>.core)rc   Úoperatorr)   Úipow)r¶   rµ   r¸   r4   r´   r5   Úcpow_implement¤  s    r»   )prs   r¹   Zllvmliter   Z
numba.corer   r   r   r   Znumba.core.imputilsr   Znumba.typesr   r	   r
   r   Z
numba.cudar   Znumbar   Úregistryrc   ZbooleansÚisnanÚisinfÚisfinitert   r   r   r   r   r   r   r   Úgammar   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   rf   r‰   r'   r(   r)   r*   r+   r,   r…   ÚIntegerr6   Útruedivr=   r>   Zfloat16rE   rG   rI   rK   rM   rO   rQ   rS   rU   rW   rY   re   rm   ry   rz   r„   rˆ   rŠ   r‹   r�   rw   rx   rd   ri   Zimpl32Zimpl64r“   ZpowifZpowir™   Zmodffr˜   r�   Zfrexpfrœ   r    ZldexpfrŸ   r­   ro   rn   r»   Z	complex64Z
complex128r4   r4   r4   r5   Ú<module>   s  



















		
