
    xKg>                        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j4                  Z ej6                   ej8                  d            Zej<                  Zej@                  Z! ej6                   ej8                  d            Z"e"j<                  Z#e"j@                  Z$dZ%dZ&dZ'dZ(d Z)d Z*d Z+d Z,d Z-d Z.d Z/d Z0d Z1d Z2d Z3d Z4dfdZ5 e4ejl                  d        e4ejn                  d      Z8 e4ejr                  d       Z: e4ejv                  d!      Z< e4ejz                  d"      Z> e4ej~                  d#      Z@ e4ej                  d$      ZB e5ej                  d%d&      ZD e5ej                  d'd(      ZF e5ej                  d)d*      ZH e5ej                  d+d,      ZJ e5ej                  d-d.      ZL e5ej                  d/d0      ZN e5ej                  d1d2      ZP e5ej                  d3d4      ZR e5ej                  d5d6      ZT e5ej                  d7d8      ZV e5ej                  d9d:      ZX e5ej                  d;d<      ZZ e5ej                  d=d>      Z\ e5ej                  d?d@      Z^ e5ejz                  dAdB      Z> e5ej                  dCdDdE      Z` e5ej                  dFdGdE      Zb e5ej                  dHdI      Zd e5ej                  dJdK      Zf e5ej                  dLdMdE      Zh e5ej                  dNdO      Zj eej                  ej                        dP        Zm eej                  ej                        dQ        Zo eej                  ej                        dR        Zq eej                  ej                        dS        Zr eej                  ej                        dT        Zt eej                  ej                        dU        Zu eej                  ej                  ej                        dV        Zw eej                  ej                        dW        Zy eej                  ej                  ej                        dX        Z| eej                  ej                  ej                        dY        Z eej                  ej                   ej                         dZ        Z eej                  ej                  ej                        d[        Z eej                  ej                  ej                        d\        Z eej                  ej                   ej                         d]        Z eej                  ej                  ej                        d^        Z eej                  ej                        d_        Z e3ej                  e        eej                  ej                        d`        Z e3ej                  e        eej                  ej                  ej                         eej                  ej                  ej                        da               Z eej                  ej                  ej                        db        Zdc Z ee      dd        Zde Z  eej$                  ej                  ej                        e       y)gzA
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                 (    | j                  d||      S )z<
    Return a condition testing whether *val* is a NaN.
    uno)fcmp_unorderedbuildervals     Z/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/cpython/mathimpl.pyis_nanr   (   s     !!%c22    c                     t        |j                  t        d            }t        |j                  t        d            }| j                  d||      }| j                  d||      }| j	                  ||      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isneginfs         r   is_infr#   .   se     sxxv/Gsxxv/G##D#w7H##D#w7H;;x**r   c                 L    | j                  ||      }| j                  d||      S )z?
    Return a condition testing whether *val* is a finite.
    ord)fsubr   )r   r   val_minus_vals      r   	is_finiter(   8   s)    
 LLc*M}mDDr   c                     |j                   t        j                  j                         k(  sJ | j	                  |t        j                  j                  d            S )z1
    Bitcast a double into a 64-bit integer.
    @   )r   llvmliteir
DoubleTypebitcastIntTyper   s     r   f64_as_int64r0   @   sC     88x{{--////??3 3 3B 788r   c                     |j                   t        j                  j                  d      k(  sJ | j	                  |t        j                  j                               S )z1
    Bitcast a 64-bit integer into a double.
    r*   )r   r+   r,   r/   r.   r-   r   s     r   int64_as_f64r2   G   sC     88x{{**2....??3 6 6 899r   c                     |j                   t        j                  j                         k(  sJ | j	                  |t        j                  j                  d            S )z0
    Bitcast a float into a 32-bit integer.
        )r   r+   r,   	FloatTyper.   r/   r   s     r   f32_as_int32r6   N   sC     88x{{,,....??3 3 3B 788r   c                     |j                   t        j                  j                  d      k(  sJ | j	                  |t        j                  j                               S )z0
    Bitcast a 32-bit integer into a float.
    r4   )r   r+   r,   r/   r.   r5   r   s     r   int32_as_f32r8   U   sC     88x{{**2....??3 5 5 788r   c                 N    | j                  t        |j                  d      |      S )zB
    Negate real number *val*, with proper handling of zeros.
    g       )r&   r   r   r   s     r   negate_realr:   \   s     
 <<40#66r   c                     | j                   }|j                  ||D cg c]  }|j                   c}      }| j                  ||      S c c}w )z9
    Call a LLVM intrinsic floating-point operation.
    )moduledeclare_intrinsicr   call)r   nameargsmodaintrs         r   call_fp_intrinsicrD   c   sH     ..C  '=1'=>D<<d## (>s   A	
c                       fd}|S )z
    Return an implementation factory to convert the single integral input
    argument to a float64, then defer to the *wrapped_impl*.
    c                 .   |\  }|j                   d   }| j                  |||t        j                        }t	        t        j                  t        j                        } 	| |||f      }| j                  ||t        j                  |j
                        S )Nr   )r@   castr   r   r   return_type)
contextr   sigr@   r   
input_typefpval	inner_sigreswrapped_impls
            r   implementerz2_unary_int_input_wrapper_impl.<locals>.implementerq   sr    XXa[
Wc:u}}EemmU]];	7GYA||GS%--IIr    )rO   rP   s   ` r   _unary_int_input_wrapper_implrR   l   s    
J r   c                 Z    t        |      } t        | t        j                        |       y N)rR   lowerr   Integer)fn
float_implimpls      r   unary_math_int_implrZ   {   s!    (4DE"emmT"r   c                 d    t        | t        j                        fd       }t        | |       |S )zO
    Implement the math function *fn* using the LLVM intrinsic *intrcode*.
    c                 N    t        ||      }t        | ||j                  |      S rT   )rD   r   rH   )rI   r   rJ   r@   rN   intrcodes        r   rX   z#unary_math_intr.<locals>.float_impl   s&    48!'7COOSIIr   )rU   r   FloatrZ   )rW   r]   rX   s    ` r   unary_math_intrr_      s6     2u{{J J J'r   c                     |rt         j                  nd}f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                    |\  }|j                   }|j                  d   }| j                  |      }t        j                  t        j
                  i|   }t        j                  j                  ||g      }	t        j                  |j                   |	|      }
|j                  |
|f      }| j                  ||||j                        }t        | ||j                  |      S )z9
        Implement *fn* for a types.Float input.
        r   r?   )r<   r@   get_value_typer   r   r   r+   r,   FunctionTyper
   insert_pure_functionr>   rG   rH   r   )rI   r   rJ   r@   r   rA   rK   lty	func_namefntyrW   rN   	f32extern	f64externs               r   rX   z%unary_math_extern.<locals>.float_impl   s     nnXXa[
$$Z0MM9MM9 	 {{''cU3))'..$YOll2v&ll7CS__E!'7COOSIIr   )r   int64rU   r^   rZ   )rW   ri   rj   int_restype	f_restyperX   s    ``   r   unary_math_externrn      sA      +IJ$ E"ekk:& J'r   z	llvm.fabszllvm.expz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tanhlog2flog2ceilfceilTfloorffloornumba_gammafnumba_gammasqrtfsqrttruncftrunclgammaflgammac                 R    |\  }t        ||      }t        | ||j                  |      S rT   )r   r   rH   rI   r   rJ   r@   r   rN   s         r   isnan_float_implr      *    ES
#
CgwEEr   c                 R    t         j                  }t        | ||j                  |      S rT   r
   	false_bitr   rH   rI   r   rJ   r@   rN   s        r   isnan_int_implr      "    


CgwEEr   c                 R    |\  }t        ||      }t        | ||j                  |      S rT   )r#   r   rH   r   s         r   isinf_float_implr      r   r   c                 R    t         j                  }t        | ||j                  |      S rT   r   r   s        r   isinf_int_implr      r   r   c                 R    |\  }t        ||      }t        | ||j                  |      S rT   )r(   r   rH   r   s         r   isfinite_float_implr      s*    ES
GS
!CgwEEr   c                 R    t         j                  }t        | ||j                  |      S rT   )r
   true_bitr   rH   r   s        r   isfinite_int_implr      s"    


CgwEEr   c                    |d   j                   }|j                  }t        j                  |t        j
                  j                  |||f      d|j                  z        }|j                  ||      }t        | ||j                  |      S )Nr   zllvm.copysign.%s)r   r<   r
   get_or_insert_functionr+   r,   rd   intrinsic_namer>   r   rH   )rI   r   rJ   r@   rf   rA   rW   rN   s           r   copysign_float_implr      sv    
q',,C
..C		'	'X[[-E-EcCQT:-V(:S=O=O(O
QB
,,r4
 CgwEEr   c                 :   |\  }| j                  |j                  d         }| j                  |j                  d         }t        j                  ||d      }t
        j                  j                  ||t
        j                  j                  |      f      }dddt        |         }	t        j                  |j                  ||	      }
|j                  |
||f      }t        j                  |||j                  |      f      }t        | ||j                  |      S )Nr      exprb   numba_frexpfnumba_frexpr   double)get_data_typer@   rH   r
   alloca_oncer+   r,   rd   PointerTypestrr   r<   r>   make_anonymous_structloadr   )rI   r   rJ   r@   r   flttyinttyexpptrrh   fnamerW   rN   s               r   
frexp_implr     s    DC!!#((1+.E!!#//!"45E  %e<F;;##EE8;;3J3J53Q+RSD
 e*E 
	'	'e	DB
,,rC=
)C

'
'#w||F7K1L
MCgwEEr   c                 T   |\  }}t        | j                  |j                        \  }}t        j                  j                  |||f      }dddt        |         }	t        j                  |j                  ||	      }
|j                  |
||f      }t        | ||j                  |      S )Nnumba_ldexpfnumba_ldexpr   rb   )mapr   r@   r+   r,   rd   r   r
   re   r<   r>   r   rH   )rI   r   rJ   r@   r   r   r   r   rh   r   rW   rN   s               r   
ldexp_implr     s    HCw,,chh7LE5;;##EE5>:D
 e*E 
	%	%gnnd	GB
,,rC:
&CgwEEr   c                 R   |\  }}|j                  |t        j                  j                               }|j                  |t        j                  j                               }t	        t
        j                  t
        j                  t
        j                        }t        | ||||f      S rT   )sitofpr+   r,   r-   r   r   r   atan2_float_implrI   r   rJ   r@   yxfsigs          r   atan2_s64_implr   &  t    FQq(++0023Aq(++0023AU]]EMM5==ADGWdQF;;r   c                 R   |\  }}|j                  |t        j                  j                               }|j                  |t        j                  j                               }t	        t
        j                  t
        j                  t
        j                        }t        | ||||f      S rT   )uitofpr+   r,   r-   r   r   r   r   r   s          r   atan2_u64_implr   .  r   r   c                    t        |      dk(  sJ |j                  }|j                  d   }| j                  |      }t        j
                  dt        j                  di|   }t        j                  j                  |||f      }t        j                  |j                  ||      }	|j                  |	|      }
t        | ||j                  |
      S )N   r   atan2fatan2rb   )lenr<   r@   rc   r   r   r   r+   r,   rd   r
   re   r>   r   rH   )rI   r   rJ   r@   rA   tyrf   rg   rh   rW   rN   s              r   r   r   6  s    t9>>
..C	!B

 
 
$Cxw
 I ;;##C#s4D		%	%gnnd	KB
,,r4
 CgwEEr   c                    |\  }}|j                  |t        j                  j                               }|j                  |t        j                  j                               }t	        t
        j                  t
        j                  t
        j                        }t        | ||||f      }t        | ||j                  |      S rT   
r   r+   r,   r-   r   r   r   hypot_float_implr   rH   rI   r   rJ   r@   r   r   r   rN   s           r   hypot_s64_implr   I      FQq(++0023Aq(++0023AU]]EMM5==AD
7GTAq6
:CgwEEr   c                    |\  }}|j                  |t        j                  j                               }|j                  |t        j                  j                               }t	        t
        j                  t
        j                  t
        j                        }t        | ||||f      }t        | ||j                  |      S rT   r   r   s           r   hypot_u64_implr   S  r   r   c                 
   |j                   \  }}||cx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        j                  ||      t        j
                  dk(  r+t        j                  dk(  r |t        d            fd}	nfd	}	| j                  ||	||      }
t        | ||j                  |
      S )
Nwin32_hypotfhypotf_hypothypotr4   infc                 n    t        j                  |       st        j                  |      rS  | |      S rT   )mathisinf)r   r   r   
plat_hypots     r   
hypot_implz$hypot_float_impl.<locals>.hypot_impln  s*    zz!}

1
a##r   c                      | |      S rT   rQ   )r   r   r   s     r   r   z$hypot_float_impl.<locals>.hypot_impls  s    a##r   )r@   rH   r   r   sysplatformr   ExternalFunctionr	   MACHINE_BITSr   compile_internalr   )rI   r   rJ   r@   xtyytyr   r   r   r   rN   r   r   s              @@r   r   r   ]  s    xxHC#((((((DAq
 	CLLG$;y3<<7#:x 
E ''s3J
||w6#6#6"#<%,	$
	$ 
"
"7JT
BCgwEEr   c                     |\  }| j                  |j                  t        j                  dz        }|j	                  ||      }t        | ||j                  |      S N   get_constantrH   r   pifmulr   rI   r   rJ   r@   r   coefrN   s          r   radians_float_implr   |  sL    
CQ3?D
,,q$
CgwEEr   c                     |\  }| j                  |j                  dt        j                  z        }|j	                  ||      }t        | ||j                  |      S r   r   r   s          r   degrees_float_implr     sL    
CQtww?D
,,q$
CgwEEr   c                 T    | j                  t        j                  |      } |||      S rT   )get_functionoperatorpow)rI   r   rJ   r@   rY   s        r   pow_implr    s'     c2Dr   c                    t        |      dk(  sJ |j                  d   }| j                  |      }t        j                  dt        j
                  di|   }t        j                  j                  |||f      }t        j                  |j                  ||      }|j                  ||      }	t        | ||j                  |	      S )Nr   r   
nextafterf	nextafterrb   )r   r@   rc   r   r   r   r+   r,   rd   r
   re   r<   r>   r   rH   )
rI   r   rJ   r@   r   rf   rg   rh   rW   rN   s
             r   nextafter_implr	    s    t9>>	!B

 
 
$C|{
 I ;;##C#s4D		%	%gnnd	KB
,,r4
 CgwEEr   c                      y)z8Convert integer to unsigned integer of equivalent width.NrQ   Ts    r   	_unsignedr    s    r   c                     | t         j                  v rd S | t         j                  v r.t        t         dj	                  | j
                              fdS y )Nc                     | S rT   rQ   r  s    r   <lambda>z _unsigned_impl.<locals>.<lambda>  s    r   zuint{}c                      |       S rT   rQ   r  newTs    r   r  z _unsigned_impl.<locals>.<lambda>  s	    ar   )r   unsigned_domainsigned_domaingetattrformatbitwidthr  s    @r   _unsigned_implr    sI    E!!!	
e!!	!uhooajj9:   
"r   c                     |j                   \  }}||cxk(  r|j                  k(  sJ  J |\  }}d }| j                  ||||      }	t        | ||j                  |	      S )Nc                    t        |       }| dk(  rt        |      S |dk(  rt        |       S t        |       }t        |      }t        ||      }t	        t        t        j                  | |                  }t	        t        t        j                  ||                  }||k7  r3||kD  r||}}||z  }t        j                  |t        |            }||k7  r3t        j                   ||      |      }|S )zO
        Stein's algorithm, heavily cribbed from Julia implementation.
        r   )r   absr   minr  npright_shift
left_shift)	rB   br  zazbkuvrs	            r   gcdzgcd_impl.<locals>.gcd  s     G6#a&=6#a&=AABKc"..B/01c"..B/011f1u!1FAq."34A	 1f
 MM!A$"r   )r@   rH   r   r   )
rI   r   rJ   r@   r   r   r   r   r(  rN   s
             r   gcd_implr)    sg    xxHC#((((((DAq* 
"
"7Cd
;CgwEEr   )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   registryrU   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(   r0   r2   r6   r8   r:   rD   rR   rZ   r_   rn   fabsr   exp_implloglog_impllog10
log10_implr   	log2_implsinsin_implcoscos_implrp   
log1p_implrr   
expm1_implrt   erf_implrv   	erfc_implrx   tan_implrz   	asin_implr|   	acos_implr~   	atan_implr   
asinh_implr   
acosh_implr   
atanh_implr   	sinh_implr   	cosh_implr   	tanh_implr   	ceil_implr   
floor_implgamma
gamma_implr   	sqrt_implr   
trunc_implr   lgamma_implisnanr^   r   rV   r   r   r   r   isfiniter   r   copysignr   frexpr   ldexpintcr   r   rk   r   uint64r   r   r   r   r   r   radiansr   degreesr   r  r  r  r	  r  r  r)  r(  rQ   r   r   <module>rk     sm     
     <  4 4 ) ' 7 J ),-





),-





$% 3+E9:997$#
!H 		; '488Z0488Z0TZZ6
DII{3	488Z0488Z0tzz8W=
tzz8W=
TXXvu5dii&9	TXXvu5dii&9	dii&9	dii&9	tzz8W=
tzz8W=
tzz8W=
dii&9	dii&9	dii&9	dii&9	dii&$?	tzz8WdC
tzz>=I
dii&9	tzz8WdC
YA tzz5;;F  F
 tzz5==!F "F
 tzz5;;F  F
 tzz5==!F "F
 t}}ekk"F #F t}}emm$F %F
 t}}ekk5;;/F 0F tzz5;;F  F  tzz5;;

+
F ,
F  tzz5;;,< -< tzz5<<.< /< tzz5;;,F -F$ tzz5;;,F -F tzz5<<.F /F tzz5;;,F -F< t||U[[!F "F DLL"4 5 t||U[[!F "F DLL"4 5 txxekk*txxemm, - + t~~u{{EKK0F 1F	 
)! !F< .dhhu}} -h 7r   