o
    i4=                     @   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
 ddlmZmZmZ ddlmZ ddlmZ ddlm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 Z*dd  Z+d!d" Z,d#d$ Z-d%d& Z.dd(d)Z/e.ej0d* e.ej1d+Z2ej3d,kre.ej4d-Z5e.ej6d.Z7e.ej8d/Z9e.ej:d0Z;e.ej<d1Z=e/ej>d2d3Z?e/ej@d4d5ZAe/ejBd6d7ZCe/ejDd8d9ZEe/ejFd:d;ZGe/ejHd<d=ZIe/ejJd>d?ZKe/ejLd@dAZMe/ejNdBdCZOe/ejPdDdEZQe/ejRdFdGZSe/ejTdHdIZUe/ejVdJdKZWe/ejXdLdMZYe/ejZdNdOZ[e/ej\dPdQdRZ]e/ej^dSdTdRZ_e/ej`dUdVZae/ejbdWdXZce/ejddYdZdRZee/ejfd[d\Zgd]d^ Zhd_d` Zidadb Zjdcdd Zkdedf Zldgdh Zmdidj Zndkdl Zodmdn Zpdodp Zqdqdr Zrdsdt Zsdudv Ztdwdx Zudydz Zvd{d| Zwe-ejxew d}d~ Zye-ejzey dd Z{dd Z|ee|dd Z}dd Z~dS )zA
Provide math calls that uses intrinsics or libc math functions.
    N)Constant)impl_ret_untracked)typesconfigcgutils)overload)	signature)trailing_zeros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   T/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/numba/np/math/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   pos_inf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   val_minus_valr   r   r   	is_finite7   s   r    c                 C   (   |j tj ks
J | |tjdS )z1
    Bitcast a double into a 64-bit integer.
    @   )r   llvmliteir
DoubleTypebitcastIntTyper   r   r   r   f64_as_int64?      r(   c                 C   (   |j tjdksJ | |tj S )z1
    Bitcast a 64-bit integer into a double.
    r"   )r   r#   r$   r'   r&   r%   r   r   r   r   int64_as_f64F      r+   c                 C   r!   )z0
    Bitcast a float into a 32-bit integer.
        )r   r#   r$   	FloatTyper&   r'   r   r   r   r   f32_as_int32M   r)   r/   c                 C   r*   )z0
    Bitcast a 32-bit integer into a float.
    r-   )r   r#   r$   r'   r&   r.   r   r   r   r   int32_as_f32T   r,   r0   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   r1   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>g   s    z%call_fp_intrinsic.<locals>.<listcomp>)moduledeclare_intrinsiccall)r   nameargsmodintrr   r   r   call_fp_intrinsicb   s   r<   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   )r9   castr   r   r   return_type)	contextr   sigr9   r   
input_typefpval	inner_sigreswrapped_implr   r   implementerp   s   
z2_unary_int_input_wrapper_impl.<locals>.implementerr   )rF   rG   r   rE   r   _unary_int_input_wrapper_implk   s   rH   c                 C   s   t |}d S N)rH   )fn
float_implimplr   r   r   unary_math_int_implz   s   rM   c                    s    fdd}t | | |S )zO
    Implement the math function *fn* using the LLVM intrinsic *intrcode*.
    c                    s   t | |}t| ||j|S rI   )r<   r   r>   r?   r   r@   r9   rD   intrcoder   r   rK      s   z#unary_math_intr.<locals>.float_impl)rM   )rJ   rP   rK   r   rO   r   unary_math_intr~   s   
rQ   Fc                    s@   t jr|rtjnd}n|rtjnd} fdd}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   r8   )r5   r9   get_value_typer   r
   r   r#   r$   FunctionTyper   insert_pure_functionr7   r=   r>   r   )r?   r   r@   r9   r   r:   rA   lty	func_namefntyrJ   rD   	f32extern	f64externr   r   rK      s   

z%unary_math_extern.<locals>.float_impl)r   USE_LEGACY_TYPE_SYSTEMr   int64np_int64rM   )rJ   rZ   r[   int_restype	f_restyperK   r   rY   r   unary_math_extern   s   
ra   z	llvm.fabszllvm.exp)      z	llvm.exp2z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floornumba_gammafnumba_gammasqrtfsqrttruncftrunclgammaflgammac                 C       |\}t ||}t| ||j|S rI   )r   r   r>   r?   r   r@   r9   r   rD   r   r   r   isnan_float_impl      
r   c                 C      t j}t| ||j|S rI   r   	false_bitr   r>   rN   r   r   r   isnan_int_impl      r   c                 C   r   rI   )r   r   r>   r   r   r   r   isinf_float_impl   r   r   c                 C   r   rI   r   rN   r   r   r   isinf_int_impl   r   r   c                 C   r   rI   )r    r   r>   r   r   r   r   isfinite_float_impl   r   r   c                 C   r   rI   )r   true_bitr   r>   rN   r   r   r   isfinite_int_impl   r   r   c                 C   sN   |d j }|j}t|tj|||fd|j }|||}t	| ||j
|S )Nr   zllvm.copysign.%s)r   r5   r   get_or_insert_functionr#   r$   rT   intrinsic_namer7   r   r>   )r?   r   r@   r9   rV   r:   rJ   rD   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      exprR   numba_frexpfnumba_frexpr   double)get_data_typer9   r>   r   alloca_oncer#   r$   rT   PointerTypestrr   r5   r7   make_anonymous_structloadr   )r?   r   r@   r9   r   flttyinttyexpptrrX   fnamerJ   rD   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 )Nnumba_ldexpfnumba_ldexpr   rR   )mapr   r9   r#   r$   rT   r   r   rU   r5   r7   r   r>   )r?   r   r@   r9   r   r   r   r   rX   r   rJ   rD   r   r   r   
ldexp_impl  s   r   c                 C   P   |\}}| |tj }| |tj }ttjtjtj}t| ||||fS rI   )sitofpr#   r$   r%   r   r   r   atan2_float_implr?   r   r@   r9   yxfsigr   r   r   atan2_s64_impl*  
   r   c                 C   r   rI   )uitofpr#   r$   r%   r   r   r   r   r   r   r   r   atan2_u64_impl2  r   r   c                 C   s~   t |dksJ |j}|jd }| |}tjdtjdi| }tj	|||f}t
j|j||d}	||	|}
t| ||j|
S )N   r   atan2fatan2rR   )lenr5   r9   rS   r   r
   r   r#   r$   rT   r   rU   r7   r   r>   )r?   r   r@   r9   r:   tyrV   rW   rX   rJ   rD   r   r   r   r   :  s   

r   c                 C   `   |\}}| |tj }| |tj }ttjtjtj}t| ||||f}t| ||j	|S rI   
r   r#   r$   r%   r   r   r   hypot_float_implr   r>   r?   r   r@   r9   r   r   r   rD   r   r   r   hypot_s64_implM     r   c                 C   r   rI   r   r   r   r   r   hypot_u64_implW  r   r   c                    s   |j \}}||  kr|jksJ  J |\}}tjtjdkr!dndtjtjdkr+dndi| }t||tjdkrNtj	dkrN|t
d  fdd	}	nfd
d	}	| ||	||}
t| ||j|
S )Nwin32_hypotfhypotf_hypothypotr-   infc                    s"   t | s
t |r S | |S rI   )mathisinfr   r   r   
plat_hypotr   r   
hypot_implq  s   
z$hypot_float_impl.<locals>.hypot_implc                    s
    | |S rI   r   r   )r   r   r   r   v  s   
)r9   r>   r   r
   sysplatformr   ExternalFunctionr   MACHINE_BITSr   compile_internalr   )r?   r   r@   r9   xtyytyr   r   r   r   rD   r   r   r   r   a  s   
r   c                 C   s6   |\}|  |jtjd }|||}t| ||j|S N   get_constantr>   r   pifmulr   r?   r   r@   r9   r   coefrD   r   r   r   radians_float_impl     r   c                 C   s6   |\}|  |jdtj }|||}t| ||j|S r   r   r   r   r   r   degrees_float_impl  r   r   c                 C   s   |  tj|}|||S rI   )get_functionoperatorpow)r?   r   r@   r9   rL   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v r	dd S | t jv rtt d| j  fddS d S )Nc                 S   s   | S rI   r   r   r   r   r   <lambda>  s    z _unsigned_impl.<locals>.<lambda>zuint{}c                    s    | S rI   r   r   newTr   r   r     s    )r   unsigned_domainsigned_domaingetattrformatbitwidthr   r   r   r   _unsigned_impl  s   

r   c           
      C   sX   |j \}}||  kr|jksJ  J |\}}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rR||krB||}}||8 }t|t|}||ks9t|||}|S )zO
        Stein's algorithm, heavily cribbed from Julia implementation.
        r   )r   absr	   minr   npright_shift
left_shift)	r3   br   zazbkuvrr   r   r   gcd  s    

zgcd_impl.<locals>.gcd)r9   r>   r   r   )
r?   r   r@   r9   r   r   r   r   r  rD   r   r   r   gcd_impl  s   
r  )F)__doc__r   r   r   numpyr   llvmlite.irr#   r   numba.core.imputilsr   
numba.corer   r   r   numba.core.extendingr   numba.core.typingr   numba.cpython.unsafe.numbersr	   finfodtype_NP_FLT_FINFOmaxFLT_MAXtinyFLT_MIN_NP_DBL_FINFODBL_MAXDBL_MINFLOAT_ABS_MASKFLOAT_SIGN_MASKDOUBLE_ABS_MASKDOUBLE_SIGN_MASKr   r   r    r(   r+   r/   r0   r1   r<   rH   rM   rQ   ra   fabsr   exp_implversion_infoexp2	exp2_implloglog_impllog10
log10_implsinsin_implcoscos_implre   
log1p_implrg   
expm1_implri   erf_implrk   	erfc_implrm   tan_implro   	asin_implrq   	acos_implrs   	atan_implru   
asinh_implrw   
acosh_implry   
atanh_implr{   	sinh_implr}   	cosh_implr   	tanh_implr   	log2_implr   	ceil_implr   
floor_implgamma
gamma_implr   	sqrt_implr   
trunc_implr   lgamma_implr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   radiansr   degreesr   r   r   r  r   r   r   r   <module>   s    
	
'



