
    xKgl<                        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j*                   ej,                  d	            Zej0                  Zej4                  Z ej*                   ej,                  d
            Zej0                  Zej4                  ZdZdZ dZ!dZ"d Z#d Z$d Z%d Z&d Z'd Z(d Z)d Z*d Z+d Z,d Z-d Z.dbdZ/ e.ej`                  d        e.ejb                  d      Z2 e.ejf                  d      Z4 e.ejj                  d      Z6 e.ejn                  d       Z8 e.ejr                  d!      Z: e/ejv                  d"d#      Z< e/ejz                  d$d%      Z> e/ej~                  d&d'      Z@ e/ej                  d(d)      ZB e/ej                  d*d+      ZD e/ej                  d,d-      ZF e/ej                  d.d/      ZH e/ej                  d0d1      ZJ e/ej                  d2d3      ZL e/ej                  d4d5      ZN e/ej                  d6d7      ZP e/ej                  d8d9      ZR e/ej                  d:d;      ZT e/ej                  d<d=      ZV e/ej                  d>d?      ZX e/ej                  d@dAdB      ZZ e/ej                  dCdDdB      Z\ e/ej                  dEdF      Z^ e/ej                  dGdH      Z` e/ej                  dIdJdB      Zb e/ej                  dKdL      ZddM ZedN ZfdO ZgdP ZhdQ ZidR ZjdS ZkdT ZldU ZmdV ZndW ZodX ZpdY ZqdZ Zrd[ Zsd\ Zt e-ej                  et       d] Zv e-ej                  ev       d^ Zxd_ Zy eey      d`        Zzda Z{y)czA
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                 (    | 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/np/math/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$   7   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_int64r,   ?   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_f64r.   F   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_int32r2   M   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.
    r0   )r   r'   r(   r+   r*   r1   r   s     r   int32_as_f32r4   T   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_realr6   [   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_intrinsicr@   b   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>.implementerp   sr    XXa[
Wc:u}}EemmU]];	7GYA||GS%--IIr    )rK   rL   s   ` r   _unary_int_input_wrapper_implrN   k   s    
J r   c                     t        |      }y N)rN   )fn
float_implimpls      r   unary_math_int_implrT   z   s    (4Dr   c                 *    fd}t        | |       |S )zO
    Implement the math function *fn* using the LLVM intrinsic *intrcode*.
    c                 N    t        ||      }t        | ||j                  |      S rP   )r@   r   rD   )rE   r   rF   r<   rJ   intrcodes        r   rR   z#unary_math_intr.<locals>.float_impl   s&    48!'7COOSIIr   )rT   )rQ   rW   rR   s    ` r   unary_math_intrrX   ~   s    
J J'r   c                 V    |rt         j                  nd}f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                    |\  }|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;   )r8   r<   get_value_typer   r   r   r'   r(   FunctionTyper   insert_pure_functionr:   rC   rD   r   )rE   r   rF   r<   r   r=   rG   lty	func_namefntyrQ   rJ   	f32extern	f64externs               r   rR   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   int64rT   )rQ   rb   rc   int_restype	f_restyperR   s    ``   r   unary_math_externrg      s*      +IJ* J'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floornumba_gammafnumba_gammasqrtfsqrttruncftrunclgammaflgammac                 R    |\  }t        ||      }t        | ||j                  |      S rP   )r   r   rD   rE   r   rF   r<   r   rJ   s         r   isnan_float_implr      *    ES
#
CgwEEr   c                 R    t         j                  }t        | ||j                  |      S rP   r   	false_bitr   rD   rE   r   rF   r<   rJ   s        r   isnan_int_implr      "    


CgwEEr   c                 R    |\  }t        ||      }t        | ||j                  |      S rP   )r   r   rD   r   s         r   isinf_float_implr      r   r   c                 R    t         j                  }t        | ||j                  |      S rP   r   r   s        r   isinf_int_implr      r   r   c                 R    |\  }t        ||      }t        | ||j                  |      S rP   )r$   r   rD   r   s         r   isfinite_float_implr      s*    ES
GS
!CgwEEr   c                 R    t         j                  }t        | ||j                  |      S rP   )r   true_bitr   rD   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   r8   r   get_or_insert_functionr'   r(   r]   intrinsic_namer:   r   rD   )rE   r   rF   r<   r_   r=   rQ   rJ   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      expr[   numba_frexpfnumba_frexpr   double)get_data_typer<   rD   r   alloca_oncer'   r(   r]   PointerTypestrr   r8   r:   make_anonymous_structloadr   )rE   r   rF   r<   r   flttyinttyexpptrra   fnamerQ   rJ   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   r[   )mapr   r<   r'   r(   r]   r   r   r^   r8   r:   r   rD   )rE   r   rF   r<   r   r   r   r   ra   r   rQ   rJ   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 rP   )sitofpr'   r(   r)   r	   r   r   atan2_float_implrE   r   rF   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 rP   )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atan2r[   )lenr8   r<   r\   r   r   r   r'   r(   r]   r   r^   r:   r   rD   )rE   r   rF   r<   r=   tyr_   r`   ra   rQ   rJ   s              r   r   r   5  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 rP   
r   r'   r(   r)   r	   r   r   hypot_float_implr   rD   rE   r   rF   r<   r   r   r   rJ   s           r   hypot_s64_implr   H      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 rP   r   r   s           r   hypot_u64_implr   R  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hypotr0   infc                 n    t        j                  |       st        j                  |      rS  | |      S rP   )mathisinf)r   r   r   
plat_hypots     r   
hypot_implz$hypot_float_impl.<locals>.hypot_impll  s*    zz!}

1
a##r   c                      | |      S rP   rM   )r   r   r   s     r   r   z$hypot_float_impl.<locals>.hypot_implq  s    a##r   )r<   rD   r   r   sysplatformr   ExternalFunctionr   MACHINE_BITSr   compile_internalr   )rE   r   rF   r<   xtyytyr   r   r   r   rJ   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_constantrD   r   pifmulr   rE   r   rF   r<   r   coefrJ   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 rP   )get_functionoperatorpow)rE   r   rF   r<   rS   s        r   pow_implr     s%    c2Dr   c                      y)z8Convert integer to unsigned integer of equivalent width.NrM   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 rP   rM   r   s    r   <lambda>z _unsigned_impl.<locals>.<lambda>  s    r   zuint{}c                      |       S rP   rM   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)	r>   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<   rD   r   r   )
rE   r   rF   r<   r   r   r   r   r  rJ   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   
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.   r2   r4   r6   r@   rN   rT   rX   rg   fabsr   exp_implloglog_impllog10
log10_implsinsin_implcoscos_implri   
log1p_implrk   
expm1_implrm   erf_implro   	erfc_implrq   tan_implrs   	asin_implru   	acos_implrw   	atan_implry   
asinh_implr{   
acosh_implr}   
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  rM   r   r   <module>rW     s{     
     2 - - ) ' 7 ),-





),-





$% 3+E9:997$5
!H 		; '488Z0488Z0TZZ6
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FFFFFFFF"
F"<<F&FFF>F DLL"4 5
F DLL"4 5	 
)! !Fr   