U
    9%eP8                     @   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 ZUdd ZVdd ZWeD ]8\ZXZYZZe[eeYZ\e[eeXZ]eOeZee\ eOeZee] qe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] qldd Z^e^ejej_ e^ejej` dd Zaeaejejb eaejejc dd Zdedejeje edejejf dd Zgegejejh egejeji dd Zjejejejk ejejejl eSe jleejl eSe jleejl dd 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   R/var/www/html/Darija-Ai-API/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  



















		
