U
    |ed<                     @   s  d 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 ddl	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 dd	lmZ e
d
ZejZeedZejZej Z!eedZ"e"jZ#e"j Z$dZ%dZ&dZ'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  Z0d!d" Z1d#d$ Z2d%d& Z3d'd( Z4dd*d+Z5e4ej6d, e4ej7d-Z8e4ej9d.Z:e4ej;d/Z<e4ej=d0Z>e4ej?d1Z@e5ejAd2d3ZBe5ejCd4d5ZDe5ejEd6d7ZFe5ejGd8d9ZHe5ejId:d;ZJe5ejKd<d=ZLe5ejMd>d?ZNe5ejOd@dAZPe5ejQdBdCZRe5ejSdDdEZTe5ejUdFdGZVe5ejWdHdIZXe5ejYdJdKZZe5ej[dLdMZ\e5ej]dNdOZ^e5ej_dPdQdRZ`e5ejadSdTdRZbe5ejcdUdVZde5ejedWdXZfe5ejgdYdZdRZhe5ejid[d\Zjeejkejld]d^ Zmeejkejnd_d` Zoeejpejldadb Zqeejpejndcdd Zreejsejldedf Zteejsejndgdh Zueejvejlejldidj Zweejxejldkdl Zyeejzejlej{dmdn Z|eej}ej~ej~dodp Zeej}ejejdqdr Zeej}ejlejldsdt Zeejej~ej~dudv Zeejejejdwdx Zeejejlejldydz Zeejejld{d| Ze3eje eejejld}d~ Ze3eje eejejlejleejejlejndd Zdd Zeedd Zdd Zeejejnejne dS )zA
Provide math calls that uses intrinsics or libc math functions.
    N)Constant)Registryimpl_ret_untracked)typeof)typesutilsconfigcgutils)overload)	signature)trailing_zerosmathimplfloat32float64il        l    l            c                 C   s   |  d||S )z<
    Return a condition testing whether *val* is a NaN.
    uno)fcmp_unorderedbuilderval r   S/var/www/website-v5/atlas_env/lib/python3.8/site-packages/numba/cpython/mathimpl.pyis_nan(   s    r   c                 C   sH   t |jtd}t |jtd}| d||}| d||}| ||S )zB
    Return a condition testing whether *val* is an infinite.
    z+infz-infz==)r   typefloatfcmp_orderedor_)r   r   Zpos_infZneg_infisposinfisneginfr   r   r   is_inf.   s
    r   c                 C   s   |  ||}| d||S )z?
    Return a condition testing whether *val* is a finite.
    ord)fsubr   )r   r   Zval_minus_valr   r   r   	is_finite8   s    r!   c                 C   s(   |j tj kst| |tjdS )z1
    Bitcast a double into a 64-bit integer.
    @   )r   llvmliteir
DoubleTypeAssertionErrorbitcastIntTyper   r   r   r   f64_as_int64@   s    r)   c                 C   s(   |j tjdkst| |tj S )z1
    Bitcast a 64-bit integer into a double.
    r"   )r   r#   r$   r(   r&   r'   r%   r   r   r   r   int64_as_f64G   s    r*   c                 C   s(   |j tj kst| |tjdS )z0
    Bitcast a float into a 32-bit integer.
        )r   r#   r$   	FloatTyper&   r'   r(   r   r   r   r   f32_as_int32N   s    r-   c                 C   s(   |j tjdkst| |tj S )z0
    Bitcast a 32-bit integer into a float.
    r+   )r   r#   r$   r(   r&   r'   r,   r   r   r   r   int32_as_f32U   s    r.   c                 C   s   |  t|jd|S )zB
    Negate real number *val*, with proper handling of zeros.
    g       )r    r   r   r   r   r   r   negate_real\   s    r/   c                 C   s(   | j }||dd |D }| ||S )z9
    Call a LLVM intrinsic floating-point operation.
    c                 S   s   g | ]
}|j qS r   )r   ).0ar   r   r   
<listcomp>h   s     z%call_fp_intrinsic.<locals>.<listcomp>)moduledeclare_intrinsiccall)r   nameargsmodZintrr   r   r   call_fp_intrinsicc   s    r9   c                    s    fdd}|S )z
    Return an implementation factory to convert the single integral input
    argument to a float64, then defer to the *wrapped_impl*.
    c           	         sT   |\}|j d }| |||tj}ttjtj} | |||f}| ||tj|jS )Nr   )r7   castr   r   r   return_type)	contextr   sigr7   r   
input_typeZfpval	inner_sigreswrapped_implr   r   implementerq   s    
z2_unary_int_input_wrapper_impl.<locals>.implementerr   )rB   rC   r   rA   r   _unary_int_input_wrapper_impll   s    rD   c                 C   s   t |}t| tj| d S N)rD   lowerr   Integer)fn
float_implimplr   r   r   unary_math_int_impl{   s    rK   c                    s&   t | tj fdd}t| | |S )zO
    Implement the math function *fn* using the LLVM intrinsic *intrcode*.
    c                    s   t | |}t| ||j|S rE   )r9   r   r;   r<   r   r=   r7   r@   intrcoder   r   rI      s    z#unary_math_intr.<locals>.float_impl)rF   r   FloatrK   )rH   rN   rI   r   rM   r   unary_math_intr   s    

rP   Fc                    s:   |r
t jnd} fdd}t| t j| t| | |S )a!  
    Register implementations of Python function *fn* using the
    external function named *f32extern* and *f64extern* (for float32
    and float64 inputs, respectively).
    If *int_restype* is true, then the function's return value should be
    integral, otherwise floating-point.
    Nc                    s   |\}|j }|jd }| |}tj tji| }tj||g}	t	j
|j |	|d}
||
|f}| ||||j}t| ||j|S )z9
        Implement *fn* for a types.Float input.
        r   r6   )r3   r7   get_value_typer   r   r   r#   r$   FunctionTyper	   insert_pure_functionr5   r:   r;   r   )r<   r   r=   r7   r   r8   r>   lty	func_namefntyrH   r@   	f32extern	f64externr   r   rI      s     

  z%unary_math_extern.<locals>.float_impl)r   int64rF   rO   rK   )rH   rY   rZ   Zint_restypeZ	f_restyperI   r   rX   r   unary_math_extern   s
    
r\   z	llvm.fabszllvm.expzllvm.logz
llvm.log10zllvm.sinzllvm.coslog1pflog1pexpm1fexpm1erfferferfcferfctanftanasinfasinacosfacosatanfatanasinhfasinhacoshfacoshatanhfatanhsinhfsinhcoshfcoshtanhftanhlog2flog2ceilfceilTfloorffloorZnumba_gammafZnumba_gammasqrtfsqrttruncftrunclgammaflgammac                 C   s    |\}t ||}t| ||j|S rE   )r   r   r;   r<   r   r=   r7   r   r@   r   r   r   isnan_float_impl   s    
r   c                 C   s   t j}t| ||j|S rE   r	   	false_bitr   r;   rL   r   r   r   isnan_int_impl   s    r   c                 C   s    |\}t ||}t| ||j|S rE   )r   r   r;   r   r   r   r   isinf_float_impl   s    
r   c                 C   s   t j}t| ||j|S rE   r   rL   r   r   r   isinf_int_impl   s    r   c                 C   s    |\}t ||}t| ||j|S rE   )r!   r   r;   r   r   r   r   isfinite_float_impl   s    
r   c                 C   s   t j}t| ||j|S rE   )r	   true_bitr   r;   rL   r   r   r   isfinite_int_impl   s    r   c                 C   sN   |d j }|j}t|tj|||fd|j }|||}t	| ||j
|S )Nr   zllvm.copysign.%s)r   r3   r	   get_or_insert_functionr#   r$   rS   intrinsic_namer5   r   r;   )r<   r   r=   r7   rU   r8   rH   r@   r   r   r   copysign_float_impl   s    
r   c                 C   s   |\}|  |jd }|  |jd }tj||dd}tj||tj|f}dddt	| }	t
|j||	}
||
||f}t||||f}t| ||j|S )Nr      exprQ   Znumba_frexpfZnumba_frexpr   double)get_data_typer7   r;   r	   alloca_oncer#   r$   rS   PointerTypestrr   r3   r5   make_anonymous_structloadr   )r<   r   r=   r7   r   flttyinttyZexpptrrW   fnamerH   r@   r   r   r   
frexp_impl  s    r   c                 C   sp   |\}}t | j|j\}}tj|||f}dddt| }	tj|j	||	d}
|
|
||f}t| ||j|S )NZnumba_ldexpfZnumba_ldexpr   rQ   )mapr   r7   r#   r$   rS   r   r	   rT   r3   r5   r   r;   )r<   r   r=   r7   r   r   r   r   rW   r   rH   r@   r   r   r   
ldexp_impl  s    r   c                 C   sP   |\}}| |tj }| |tj }ttjtjtj}t| ||||fS rE   )sitofpr#   r$   r%   r   r   r   atan2_float_implr<   r   r=   r7   yxfsigr   r   r   atan2_s64_impl%  s
    r   c                 C   sP   |\}}| |tj }| |tj }ttjtjtj}t| ||||fS rE   )uitofpr#   r$   r%   r   r   r   r   r   r   r   r   atan2_u64_impl-  s
    r   c                 C   s~   t |dkst|j}|jd }| |}tjdtjdi| }tj	
|||f}tj|j||d}	||	|}
t| ||j|
S )N   r   atan2fatan2rQ   )lenr&   r3   r7   rR   r   r   r   r#   r$   rS   r	   rT   r5   r   r;   )r<   r   r=   r7   r8   tyrU   rV   rW   rH   r@   r   r   r   r   5  s    

  r   c                 C   s`   |\}}| |tj }| |tj }ttjtjtj}t| ||||f}t| ||j	|S rE   
r   r#   r$   r%   r   r   r   hypot_float_implr   r;   r<   r   r=   r7   r   r   r   r@   r   r   r   hypot_s64_implH  s    r   c                 C   s`   |\}}| |tj }| |tj }ttjtjtj}t| ||||f}t| ||j	|S rE   r   r   r   r   r   hypot_u64_implR  s    r   c                    s   |j \}}||  kr |jks&n t|\}}tjtjdkr@dndtjtjdkrTdndi| }t||tjdkrt	j
dkr|td  fdd	}	nfd
d	}	| ||	||}
t| ||j|
S )Nwin32Z_hypotfZhypotfZ_hypothypotr+   infc                    s"   t | st |r S | |S rE   )mathisinfr   r   r   
plat_hypotr   r   
hypot_implm  s    z$hypot_float_impl.<locals>.hypot_implc                    s
    | |S rE   r   r   )r   r   r   r   r  s    )r7   r;   r&   r   r   sysplatformr   ExternalFunctionr   MACHINE_BITSr   compile_internalr   )r<   r   r=   r7   xtyytyr   r   r   r   r@   r   r   r   r   \  s"    
  r   c                 C   s6   |\}|  |jtjd }|||}t| ||j|S N   get_constantr;   r   pifmulr   r<   r   r=   r7   r   coefr@   r   r   r   radians_float_impl{  s    r   c                 C   s6   |\}|  |jdtj }|||}t| ||j|S r   r   r   r   r   r   degrees_float_impl  s    r   c                 C   s   |  tj|}|||S rE   )get_functionoperatorpow)r<   r   r=   r7   rJ   r   r   r   pow_impl  s    r   c                 C   s   dS )z8Convert integer to unsigned integer of equivalent width.Nr   Tr   r   r   	_unsigned  s    r   c                    s>   | t jkrdd S | t jkr:tt d| j  fddS d S )Nc                 S   s   | S rE   r   r   r   r   r   <lambda>      z _unsigned_impl.<locals>.<lambda>zuint{}c                    s    | S rE   r   r   ZnewTr   r   r     r   )r   unsigned_domainsigned_domaingetattrformatbitwidthr   r   r   r   _unsigned_impl  s
    

r   c           
      C   sV   |j \}}||  kr |jks&n t|\}}dd }| ||||}	t| ||j|	S )Nc           	      S   s   t | }| dkrt|S |dkr(t| S t| }t|}t||}ttt| |}ttt||}||kr||kr|| }}||8 }t|t|}qjt|||}|S )zO
        Stein's algorithm, heavily cribbed from Julia implementation.
        r   )r   absr   minr   npright_shift
left_shift)	r1   br   ZzaZzbkuvrr   r   r   gcd  s"      

zgcd_impl.<locals>.gcd)r7   r;   r&   r   r   )
r<   r   r=   r7   r   r   r   r   r   r@   r   r   r   gcd_impl  s    
r   )F)__doc__r   r   r   numpyr   llvmlite.irr#   r   numba.core.imputilsr   r   numbar   
numba.corer   r   r   r	   numba.core.extendingr
   numba.core.typingr   numba.cpython.unsafe.numbersr   registryrF   finfodtypeZ_NP_FLT_FINFOmaxFLT_MAXtinyFLT_MINZ_NP_DBL_FINFODBL_MAXZDBL_MINZFLOAT_ABS_MASKZFLOAT_SIGN_MASKZDOUBLE_ABS_MASKZDOUBLE_SIGN_MASKr   r   r!   r)   r*   r-   r.   r/   r9   rD   rK   rP   r\   fabsr   exp_implloglog_impllog10
log10_implsinsin_implcoscos_implr^   
log1p_implr`   
expm1_implrb   Zerf_implrd   Z	erfc_implrf   tan_implrh   	asin_implrj   	acos_implrl   	atan_implrn   
asinh_implrp   
acosh_implrr   
atanh_implrt   	sinh_implrv   	cosh_implrx   	tanh_implrz   Z	log2_implr|   Z	ceil_implr~   Z
floor_implgamma
gamma_implr   	sqrt_implr   Z
trunc_implr   Zlgamma_implisnanrO   r   rG   r   r   r   r   isfiniter   r   copysignr   frexpr   ldexpintcr   r   r[   r   uint64r   r   r   r   r   r   radiansr   degreesr   r   r   r   r   r   r   r   r   r   r   <module>   s   
	
$












	
	



