o
    Nôj¦@  ã                   @   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(„ Z4dŒd*d+„Z5e4ej6d,ƒ e4ej7d-ƒZ8ej9d.kr¿e4ej:d/ƒZ;e4ej<d0ƒZ=e4ej>d1ƒZ?e4ej@d2ƒZAe4ejBd3ƒZCe4ejDd4ƒZEe5ejFd5d6ƒZGe5ejHd7d8ƒZIe5ejJd9d:ƒZKe5ejLd;d<ƒZMe5ejNd=d>ƒZOe5ejPd?d@ƒZQe5ejRdAdBƒZSe5ejTdCdDƒZUe5ejVdEdFƒZWe5ejXdGdHƒZYe5ejZdIdJƒZ[e5ej\dKdLƒZ]e5ej^dMdNƒZ_e5ej`dOdPƒZae5ej@dQdRƒZAe5ejbdSdTdUƒZce5ejddVdWdUƒZee5ejfdXdYƒZge5ejhdZd[ƒZie5ejjd\d]dUƒZke5ejld^d_ƒZmeejnejoƒd`da„ ƒZpeejnejqƒdbdc„ ƒZreejsejoƒddde„ ƒZteejsejqƒdfdg„ ƒZueejvejoƒdhdi„ ƒZweejvejqƒdjdk„ ƒZxeejyejoejoƒdldm„ ƒZzeej{ejoƒdndo„ ƒZ|eej}ejoej~ƒdpdq„ ƒZeej€ej�ej�ƒdrds„ ƒZ‚eej€ejƒejƒƒdtdu„ ƒZ„eej€ejoejoƒdvdw„ ƒZ…eej†ej�ej�ƒdxdy„ ƒZ‡eej†ejƒejƒƒdzd{„ ƒZˆeej†ejoejoƒd|d}„ ƒZ‰eejŠejoƒd~d„ ƒZ‹e3ejŠe‹ƒ eejŒejoƒd€d�„ ƒZ�e3ejŒe�ƒ eejŽejoejoƒeejŽejoejqƒd‚dƒ„ ƒƒZ�eej�ejoejoƒd„d…„ ƒZ‘d†d‡„ Z’ee’ƒdˆd‰„ ƒZ“dŠd‹„ Z”eej•ejqejqƒ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   úg/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/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   ó(   |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_f64G   ó   r,   c                 C   r"   )z0
    Bitcast a float into a 32-bit integer.
    é    )r   r$   r%   Ú	FloatTyper'   r(   r   r   r   r   Úf32_as_int32N   r*   r0   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_f32U   r-   r1   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   r2   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   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   )r:   Úcastr   r   r   Úreturn_type)	Úcontextr   Úsigr:   r   Ú
input_typeZfpvalÚ	inner_sigÚres©Úwrapped_implr   r   Úimplementerq   s   
z2_unary_int_input_wrapper_impl.<locals>.implementerr   )rE   rF   r   rD   r   Ú_unary_int_input_wrapper_impll   s   rG   c                 C   s   t |ƒ}t| tjƒ|ƒ d S ©N)rG   Úlowerr   ÚInteger)ÚfnÚ
float_implÚimplr   r   r   Úunary_math_int_impl{   s   rN   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 rH   )r<   r   r>   ©r?   r   r@   r:   rC   ©Úintrcoder   r   rL   ƒ   s   z#unary_math_intr.<locals>.float_impl)rI   r   ÚFloatrN   )rK   rQ   rL   r   rP   r   Úunary_math_intr   s   

rS   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   ©r9   )r6   r:   Úget_value_typer   r   r   r$   r%   ÚFunctionTyper	   Úinsert_pure_functionr8   r=   r>   r   )r?   r   r@   r:   r   r;   rA   ÚltyÚ	func_nameÚfntyrK   rC   ©Ú	f32externÚ	f64externr   r   rL   •   s   

þýz%unary_math_extern.<locals>.float_impl)r   Úint64rI   rR   rN   )rK   r\   r]   Zint_restypeZ	f_restyperL   r   r[   r   Úunary_math_extern‹   s
   
r_   z	llvm.fabszllvm.exp)é   é   z	llvm.exp2zllvm.logz
llvm.log10z	llvm.log2z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ÚtanhZlog2fÚlog2ÚceilfÚceilTÚfloorfÚfloorZnumba_gammafZnumba_gammaÚsqrtfÚsqrtÚtruncfÚtruncÚlgammafÚlgammac                 C   ó    |\}t ||ƒ}t| ||j|ƒS rH   )r   r   r>   ©r?   r   r@   r:   r   rC   r   r   r   Úisnan_float_implÔ   ó   
r‹   c                 C   ó   t j}t| ||j|ƒS rH   ©r	   Ú	false_bitr   r>   rO   r   r   r   Úisnan_int_implÚ   ó   r�   c                 C   r‰   rH   )r   r   r>   rŠ   r   r   r   Úisinf_float_implà   rŒ   r’   c                 C   r�   rH   rŽ   rO   r   r   r   Úisinf_int_implæ   r‘   r“   c                 C   r‰   rH   )r!   r   r>   rŠ   r   r   r   Úisfinite_float_implì   rŒ   r”   c                 C   r�   rH   )r	   Útrue_bitr   r>   rO   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   r6   r	   Úget_or_insert_functionr$   r%   rV   Úintrinsic_namer8   r   r>   )r?   r   r@   r:   rX   r;   rK   rC   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   é   ÚexprT   Znumba_frexpfZnumba_frexp©r   Údouble)Úget_data_typer:   r>   r	   Úalloca_oncer$   r%   rV   ÚPointerTypeÚstrr—   r6   r8   Úmake_anonymous_structÚloadr   )r?   r   r@   r:   r   ÚflttyÚinttyZexpptrrZ   ÚfnamerK   rC   r   r   r   Ú
frexp_impl  s   þýr§   c                 C   s€   |\}}t | j|jƒ\}}tj |||f¡}dddœt|ƒ }	tj|j	||	d�}
|
jd  
d¡ | |
||f¡}t| ||j|ƒS )NZnumba_ldexpfZnumba_ldexprœ   rT   rš   Úsignext)Úmaprž   r:   r$   r%   rV   r¡   r	   rW   r6   Úadd_attributer8   r   r>   )r?   r   r@   r:   r   r›   r¤   r¥   rZ   r¦   rK   rC   r   r   r   Ú
ldexp_impl  s   þýr«   c                 C   óP   |\}}|  |tj ¡ ¡}|  |tj ¡ ¡}ttjtjtjƒ}t| ||||fƒS rH   )Úsitofpr$   r%   r&   r   r   r   Úatan2_float_impl©r?   r   r@   r:   ÚyÚxÚfsigr   r   r   Úatan2_s64_impl.  ó
   r³   c                 C   r¬   rH   )Úuitofpr$   r%   r&   r   r   r   r®   r¯   r   r   r   Úatan2_u64_impl6  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Úatan2rT   )Úlenr6   r:   rU   r   r   r   r$   r%   rV   r	   rW   r8   r   r>   )r?   r   r@   r:   r;   ÚtyrX   rY   rZ   rK   rC   r   r   r   r®   >  s   

þýr®   c                 C   ó`   |\}}|  |tj ¡ ¡}|  |tj ¡ ¡}ttjtjtjƒ}t| ||||fƒ}t| ||j	|ƒS rH   ©
r­   r$   r%   r&   r   r   r   Úhypot_float_implr   r>   ©r?   r   r@   r:   r±   r°   r²   rC   r   r   r   Úhypot_s64_implQ  ó   rÀ   c                 C   r¼   rH   r½   r¿   r   r   r   Úhypot_u64_impl[  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Úwin32Z_hypotfZhypotfZ_hypotÚhypotr.   Úinfc                    s"   t  | ¡s
t  |¡rˆ S ˆ| |ƒS rH   )ÚmathÚisinf©r±   r°   ©rÅ   Ú
plat_hypotr   r   Ú
hypot_implv  s   
z$hypot_float_impl.<locals>.hypot_implc                    s
   ˆ | |ƒS rH   r   rÈ   )rÊ   r   r   rË   {  s   
)r:   r>   r   r   ÚsysÚplatformr   ÚExternalFunctionr   ÚMACHINE_BITSr   Úcompile_internalr   )r?   r   r@   r:   ÚxtyÚytyr±   r°   r¦   rË   rC   r   rÉ   r   r¾   e  s   
þýr¾   c                 C   s6   |\}|   |jtjd ¡}| ||¡}t| ||j|ƒS ©Né´   ©Úget_constantr>   rÆ   ÚpiÚfmulr   ©r?   r   r@   r:   r±   ÚcoefrC   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 rH   )Úget_functionÚoperatorÚpow)r?   r   r@   r:   rM   r   r   r   Úpow_implš  s   
rá   c           
      C   sx   t |ƒdksJ ‚|jd }|  |¡}tjdtjdi| }tj |||f¡}t	j
|j||d�}| ||¡}	t| ||j|	ƒS )Nr·   r   Ú
nextafterfÚ	nextafterrT   )rº   r:   rU   r   r   r   r$   r%   rV   r	   rW   r6   r8   r   r>   )
r?   r   r@   r:   r»   rX   rY   rZ   rK   rC   r   r   r   Únextafter_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 rH   r   rå   r   r   r   Ú<lambda>¹  s    z _unsigned_impl.<locals>.<lambda>zuint{}c                    s   ˆ | ƒS rH   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)	r4   Úbræ   ÚzaZzbÚkÚuÚvÚrr   r   r   ÚgcdÄ  s    

üzgcd_impl.<locals>.gcd)r:   r>   rÐ   r   )
r?   r   r@   r:   rÑ   rÒ   r±   r°   rü   rC   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   Znumba.cpython.unsafe.numbersr   ÚregistryrI   Ú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,   r0   r1   r2   r<   rG   rN   rS   r_   Úfabsr›   Úexp_implÚversion_infoÚexp2Z	exp2_implÚlogÚlog_implÚlog10Ú
log10_implr~   Z	log2_implÚsinÚsin_implÚcosÚcos_implrc   Ú
log1p_implre   Ú
expm1_implrg   Zerf_implri   Z	erfc_implrk   Útan_implrm   Ú	asin_implro   Ú	acos_implrq   Ú	atan_implrs   Ú
asinh_implru   Ú
acosh_implrw   Ú
atanh_implry   Ú	sinh_implr{   Ú	cosh_implr}   Ú	tanh_implr€   Z	ceil_implr‚   Z
floor_implÚgammaZ
gamma_implr„   Ú	sqrt_implr†   Z
trunc_implrˆ   Zlgamma_implÚisnanrR   r‹   rJ   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   r   r   Ú<module>   sä    
	
$













	
	




