U
    hâËd#  ã                   @   sT   d Z ddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
 dd„ Zedd	„ ƒZdS )
aD  Contains information on how to translate different ufuncs for the CUDA
target. It is a database of different ufuncs and how each of its loops maps to
a function that implements the inner kernel of that ufunc (the inner kernel
being the per-element function).

Use get_ufunc_info() to get the information related to a ufunc.
é    N)Ú	lru_cache)Útyping)Úget_unary_impl_for_fn_and_tyÚget_binary_impl_for_fn_and_tyc                 C   s
   t ƒ |  S ©N)Úufunc_db)Z	ufunc_key© r   úJ/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/cuda/ufuncs.pyÚget_ufunc_info   s    r
   c                     s¤  ddl m} m} ddlm‰  ddlm}m}m} ‡ fdd„‰‡ fdd„‰‡fd	d
„‰‡fdd„‰‡fdd„}‡fdd„}‡fdd„}‡fdd„}‡fdd„}	‡fdd„}
‡fdd„‰‡ ‡‡‡‡fdd„}‡fdd„‰‡ ‡‡‡‡fdd „}‡fd!d"„}‡ ‡‡‡‡fd#d$„}‡fd%d&„}‡fd'd(„}‡fd)d*„}i }ˆˆ||d+œ|tj	< ˆˆ||d+œ|tj
< ||| j| jd+œ|tj< ||| j| jd+œ|tj< ||| j| jd+œ|tj< ||| j| jd+œ|tj< |	|	d,œ|tj< |
|
d,œ|tj< ˆˆ||d+œ|tj< ˆˆ||d+œ|tj< ||||d+œ|tj< ||| j| jd+œ|tj< ||||d+œ|tj< ||| j| jd+œ|tj< |j|jd-œ|tj< |tj |tj< |j |j d-œ|tj!< |tj! |tj"< |S ).Nr   )Ú	cmathimplÚmathimpl©Ú_check_arity_and_homogeneity)Únp_complex_acosh_implÚnp_complex_cos_implÚnp_complex_sin_implc                    s*   ˆ ||dƒ t | |jd ƒ}|||||ƒS )Né   r   )r   Úargs©ÚfnÚcontextÚbuilderÚsigr   Úimplr   r   r	   Únp_unary_impl   s    zufunc_db.<locals>.np_unary_implc                    s*   ˆ ||dƒ t | |jd ƒ}|||||ƒS )Né   r   )r   r   r   r   r   r	   Únp_binary_impl"   s    z ufunc_db.<locals>.np_binary_implc                    s   ˆ t j| |||ƒS r   )ÚmathÚsin©r   r   r   r   ©r   r   r	   Únp_real_sin_impl'   s    z"ufunc_db.<locals>.np_real_sin_implc                    s   ˆ t j| |||ƒS r   )r   Úcosr   r    r   r	   Únp_real_cos_impl*   s    z"ufunc_db.<locals>.np_real_cos_implc                    s   ˆ t j| |||ƒS r   )r   Útanr   r    r   r	   Únp_real_tan_impl-   s    z"ufunc_db.<locals>.np_real_tan_implc                    s   ˆ t j| |||ƒS r   )r   Úasinr   r    r   r	   Únp_real_asin_impl0   s    z#ufunc_db.<locals>.np_real_asin_implc                    s   ˆ t j| |||ƒS r   )r   Úacosr   r    r   r	   Únp_real_acos_impl3   s    z#ufunc_db.<locals>.np_real_acos_implc                    s   ˆ t j| |||ƒS r   )r   Úatanr   r    r   r	   Únp_real_atan_impl6   s    z#ufunc_db.<locals>.np_real_atan_implc                    s   ˆ t j| |||ƒS r   )r   Úatan2r   ©r   r   r	   Únp_real_atan2_impl9   s    z$ufunc_db.<locals>.np_real_atan2_implc                    s   ˆ t j| |||ƒS r   )r   Úhypotr   r-   r   r	   Únp_real_hypot_impl<   s    z$ufunc_db.<locals>.np_real_hypot_implc                    s   ˆ t j| |||ƒS r   )r   Úsinhr   r    r   r	   Únp_real_sinh_impl?   s    z#ufunc_db.<locals>.np_real_sinh_implc                    sº   ˆ ||dƒ |j d }|j}tj|gd Ž }|  |||d ¡}|  ||¡}|j}	|j}
ˆ| |||
gƒ}ˆ| |||	gƒ}ˆ| |||
gƒ}ˆ| |||	gƒ}| ||¡|_| ||¡|_| ¡ S ©Nr   r   r   ©	r   Úunderlying_floatr   Ú	signatureÚmake_complexÚrealÚimagÚfmulÚ	_getvalue)r   r   r   r   ÚtyÚftyÚfsig1ÚxÚoutÚxrÚxiÚsxiÚshxrÚcxiÚchxr©r   r#   Únp_real_cosh_implr!   r2   r   r	   Únp_complex_sinh_implB   s    
z&ufunc_db.<locals>.np_complex_sinh_implc                    s   ˆ t j| |||ƒS r   )r   Úcoshr   r    r   r	   rH   Y   s    z#ufunc_db.<locals>.np_real_cosh_implc                    sº   ˆ ||dƒ |j d }|j}tj|gd Ž }|  |||d ¡}|  ||¡}|j}	|j}
ˆ| |||
gƒ}ˆ| |||	gƒ}ˆ| |||
gƒ}ˆ| |||	gƒ}| ||¡|_| ||¡|_| ¡ S r3   r4   )r   r   r   r   r<   r=   r>   r?   r@   rA   rB   rE   rF   rC   rD   rG   r   r	   Únp_complex_cosh_impl\   s    
z&ufunc_db.<locals>.np_complex_cosh_implc                    s   ˆ t j| |||ƒS r   )r   Útanhr   r    r   r	   Únp_real_tanh_impls   s    z#ufunc_db.<locals>.np_real_tanh_implc                    sn  ˆ ||dƒ |j d }|j}tj|gd Ž }|  |d¡}|  |||d ¡}|  ||¡}	|j}
|j}ˆ| |||gƒ}ˆ| |||gƒ}ˆ| |||
gƒ}ˆ| |||
gƒ}| ||¡}| ||¡}| ||¡}| ||¡}| ||¡}| ||¡}| 	||¡}| 
||¡}| ||¡}| ||¡}| ||¡}| ||¡}| 	||¡}| ||¡}| ||¡|	_| ||¡|	_|	 ¡ S )Nr   r   r   g      ð?)r   r5   r   r6   Zget_constantr7   r8   r9   r:   ZfaddZfdivZfsubr;   )r   r   r   r   r<   r=   r>   ZONEr?   r@   rA   rB   ÚsiÚciZshrZchr_ÚrsÚis_ÚrcZicZsqr_rcZsqr_icÚdZinv_dZrs_rcZis_icZis_rcZrs_icZnumrZnumirG   r   r	   Únp_complex_tanh_implv   s<    
z&ufunc_db.<locals>.np_complex_tanh_implc                    s   ˆ t j| |||ƒS r   )r   Úasinhr   r    r   r	   Únp_real_asinh_implœ   s    z$ufunc_db.<locals>.np_real_asinh_implc                    s   ˆ t j| |||ƒS r   )r   Úacoshr   r    r   r	   Únp_real_acosh_implŸ   s    z$ufunc_db.<locals>.np_real_acosh_implc                    s   ˆ t j| |||ƒS r   )r   Úatanhr   r    r   r	   Únp_real_atanh_impl¢   s    z$ufunc_db.<locals>.np_real_atanh_impl)úf->fúd->dzF->FzD->D)zff->fzdd->d)r[   r\   )#Znumba.cpythonr   r   Znumba.np.npyfuncsr   r   r   r   Únpr   r"   Ztan_implr$   Z	asin_implZarcsinZ	acos_implZarccosZ	atan_implZarctanZarctan2r/   r1   rJ   rL   Z
asinh_implZarcsinhZarccoshZ
atanh_implZarctanhZradians_float_implZdeg2radÚradiansZdegrees_float_implZrad2degÚdegrees)r   r   r   r   r   r%   r'   r)   r+   r.   r0   rI   rK   rM   rT   rV   rX   rZ   Údbr   )r   r   r#   rH   r!   r2   r   r	   r      sÄ    &üüüüüüþþüüüüüüþþr   )Ú__doc__r   Únumpyr]   Ú	functoolsr   Z
numba.corer   Znumba.cuda.mathimplr   r   r
   r   r   r   r   r	   Ú<module>   s   