o
    �ôjF=  ã                   @   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.d‡d(d)„Z/e.ej0d*ƒ e.ej1d+ƒZ2ej3d,kr®e.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{d�d‚„ Z|ee|ƒdƒd„„ ƒZ}d…d†„ 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   úg/var/www/html/academy/tools/voices/clone/sv-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*   |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   Úint64rM   )rJ   rZ   r[   Úint_restypeÚ	f_restyperK   r   rY   r   Úunary_math_externŠ   s   
r_   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   s€   |\}}t | j|jƒ\}}tj |||f¡}dddœt|ƒ }	tj|j	||	d�}
|
jd  
d¡ | |
||f¡}t| ||j|ƒS )NÚnumba_ldexpfÚnumba_ldexpr¡   rR   r�   Úsignext)Úmapr£   r9   r#   r$   rT   r¦   r   rU   r5   Úadd_attributer7   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   r_   Úfabsrž   Úexp_implÚversion_infoÚexp2Z	exp2_implÚlogÚlog_implÚlog10Ú
log10_implÚsinÚsin_implÚcosÚcos_implrc   Ú
log1p_implre   Ú
expm1_implrg   Úerf_implri   Ú	erfc_implrk   Útan_implrm   Ú	asin_implro   Ú	acos_implrq   Ú	atan_implrs   Ú
asinh_implru   Ú
acosh_implrw   Ú
atanh_implry   Ú	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°    
	
$



