
    i                        S r SSKrSSKJrJr  SSKrSSKJr  SSKJ	r	J
r
JrJr  SSKr\R                  " S5      r\R                  " S5      r\R                  " S5      r\R                  " \	R&                  5      r\R+                  5       r\" S5      r\" S5      r\" S5      r\" S5      rS	 rSUS
 jrS r0 rSVS jr0 4S jr  " S S\!5      r" " S S\"5      r# " S S\"5      r$ " S S\!5      r%SWS jr&S r'SXS jr(S r)S r*S r+SYS jr,S r-S r.S r/S  r0S! r1S" r2S# r3S$ r4\Rj                  " S%S&5      r6\SZS' j5       r7\S[S( j5       r8\S) 5       r9\S\S* j5       r:\S+ 5       r;SUS, jr<S- r=SUS. jr>  S]S/ jr?SUS0 jr@ S]S1 jrAS2 rBS3 rCS4 rDS5 rE\DrF\CrGS6 rH\S7\4S8 j5       rIS9 rJS: rKSUS; jrL\S^S< j5       rM\KrNS= rOS> rPS? rQS@ rRSA rSSUSB jrTSC rUSD rVS_SE jrWSF rXSG rYSH rZSI r[S`SJ jr\S`SK jr]SL r^SM r_SN r`SO raSP rbSQ rcSR rdSS reST rfg)az+
Generic helpers for LLVM code generation.
    N)contextmanager	ExitStack)ir)utilstypesconfig	debuginfo          c                 D    U R                  SXR                  S5      5      $ )N!=r   )icmp_unsignedtypebuildervalues     M/var/www/html/trading/venv/lib/python3.13/site-packages/numba/core/cgutils.pyas_bool_bitr      s      ujjm<<    c                     Uc0  [         R                  " U Vs/ s H  o3R                  PM     sn5      nU" [         R                  5      n[	        U5       H  u  pSU R                  XCU5      nM     U$ s  snf )z@
Create an anonymous struct containing the given LLVM *values*.
r   LiteralStructTyper   	Undefined	enumerateinsert_value)r   valuesstruct_typev
struct_valis         r   make_anonymous_structr"       sh     **F+CFqFFF+CDR\\*J&!))*;
 "	 ,Ds   A2c                     [        U 5      n[        U5      n[        R                  " [        R                  " [        R
                  " S5      U5      U5      $ )z(
Make a byte array constant from *buf*.
r   )	bytearraylenr   Constant	ArrayTypeIntType)bufbns      r   make_bytearrayr,   ,   s:     	#AAA;;r||BJJqM15q99r   c                     X4n[         R                  U5      nUcL  [        [        S.U   nUR                  S-   [        U 5      -   nU4n[        U S9n[        XVU5      nU[         U'   U$ )zC
Returns a specialized StructProxy subclass for the given fe_type.
)r   data_)_fe_type)_struct_proxy_cachegetValueStructProxyDataStructProxy__name__strdictr   )fe_typekind	cache_keyresbaseclsnamebases
clsmemberss           r   create_struct_proxyr@   8   s{     I

!
!)
,C
{)' --#%G47+
7:.),I&Jr   c                     UR                  5       nUR                  R                   H*  nUR                  U[	        X5      5      n[        XU5        M,     UR                  5        H  u  p4[        XU5        M     U $ )zB
Copy structure from *src* to *dst* with replacement from *repl*.
)copy
_datamodel_fieldspopgetattrsetattritems)dstsrcreplkr   s        r   copy_structrM   K   sd     99;D^^##HHQ( $ 

 Jr   c                      ^  \ rS rSrSrSrSS jrS rS rS r	S r
S	 rS
 rS rU 4S jrS rS rS rS rS rS rSrU =r$ )_StructProxyZ   z
Creates a `Structure` like interface that is constructed with information
from DataModel instance.  FE type must have a data model that is a
subclass of StructModel.
Nc                 |   Xl         U R                   R                  U R                     U l        [	        U R                  [
        R                  R                  R                  5      (       d$  [        SR                  U R                  5      5      eX l        U R                  U R                  5      U l        [        U R                  5      (       a   eU R                  U5      u  pTUR                   R"                  U R                  :w  a5  [%        SU R                  R'                  5       < SUR                   < 35      eUbp  UR                   UR                   R"                  :w  a1  [%        SUR                   R"                  < SUR                   < 35      eU R                  R)                  X55        X@l        XPl        g )NzNot a structure model: {0}zbad ref type: expected z, got zbad value type: expected )_contextdata_model_managerr0   rC   
isinstancenumbacore	datamodelStructModel	TypeErrorformat_builder_get_be_type_be_type
is_pointer
_make_refsr   pointeeAssertionError
as_pointerstore_value
_outer_ref)selfcontextr   r   ref	outer_refs         r   __init___StructProxy.__init__c   sF   --::4==I$//5::+?+?+K+KLL,33DOODF F))$//:dmm,,,,-	88t}}, $(MM$<$<$>"J K K zzY^^333$(1(>(>

&L M MMM1#r   c                 L    Uc  [        U R                  U R                  SS9nX4$ )zy
Return an (outer ref, value ref) pair.  By default, these are
the same pointers, but a derived class may override this.
Tzfill)alloca_oncer[   r]   )rf   rh   s     r   r_   _StructProxy._make_refs|   s&    
 ;dmmT]]$GCxr   c                     [         eNNotImplementedErrorrf   rW   s     r   r\   _StructProxy._get_be_type       !!r   c                     [         err   rs   rf   indexvals      r   _cast_member_to_value"_StructProxy._cast_member_to_value   rw   r   c                     [         err   rs   ry   s      r   _cast_member_from_value$_StructProxy._cast_member_from_value   rw   r   c                 F    [        U R                  U R                  SU5      $ Nr   )gep_inboundsr[   rd   rf   rz   s     r   _get_ptr_by_index_StructProxy._get_ptr_by_index   s    DMM4;;5AAr   c                 Z    U R                   R                  U5      nU R                  U5      $ rr   )rC   get_field_positionr   )rf   attrnamerz   s      r   _get_ptr_by_name_StructProxy._get_ptr_by_name   s'    228<%%e,,r   c                 ~    UR                  S5      (       d  X R                  R                  U5         $ [        U5      ez+
Load the LLVM value of the named *field*.
r/   )
startswithrC   r   AttributeErrorrf   fields     r   __getattr___StructProxy.__getattr__   s8     $$::5ABB ''r   c                    > UR                  S5      (       a  [        [        U ]  X5      $ X U R                  R                  U5      '   gz0
Store the LLVM *value* into the named *field*.
r/   N)r   superrO   __setattr__rC   r   rf   r   r   	__class__s      r   r   _StructProxy.__setattr__   s?     C  t8FF:?T__//67r   c                 x    U R                   R                  U R                  U5      5      nU R                  X5      $ z.
Load the LLVM value of the field at *index*.
)r[   loadr   r|   )rf   rz   
member_vals      r   __getitem___StructProxy.__getitem__   s4     ]]''(>(>u(EF
))%<<r   c           	      r   U R                  U5      nU R                  X5      nUR                  UR                  R                  :w  a  [	        UR                  5      (       a  [	        UR                  R                  5      (       a~  UR                  R                  UR                  R                  R                  :X  aF  U R
                  R                  U R                  UUR                  R                  R                  5      nO[        SR                  X#U US95      eU R                  R                  X#5        g)3
Store the LLVM *value* into the field at *index*.
zjInvalid store of {value.type} to {ptr.type.pointee} in {self._datamodel} (trying to write member #{index}))r   ptrrf   rz   N)r   r   r   r`   r^   rR   addrspacecastr[   	addrspacerY   rZ   rc   )rf   rz   r   r   s       r   __setitem___StructProxy.__setitem__   s     $$U+,,U:::)))5::&&:chh6F6F+G+G

**chh.>.>.F.FF 33DMM4947HH4D4D4N4NP   !D "(e4.3 "( "5	6 6 	E'r   c                 .    U R                   R                  $ z
Return the number of fields.
)rC   field_countrf   s    r   __len___StructProxy.__len__   s     ***r   c                     U R                   $ z6
Return the LLVM pointer to the underlying structure.
)re   r   s    r   _getpointer_StructProxy._getpointer   s     r   c                 L    U R                   R                  U R                  5      $ z=
Load and return the value of the underlying LLVM structure.
)r[   r   re   r   s    r   	_getvalue_StructProxy._getvalue   s     }}!!$//22r   c                     [        UR                  5      (       a   eUR                  U R                  :X  d   UR                  U R                  45       eU R                  R	                  XR
                  5        g)z$
Store the value in this structure.
N)r^   r   r]   r[   rc   rd   rf   r   s     r   	_setvalue_StructProxy._setvalue   sW     ejj))))zzT]]*GUZZ,GG*E;;/r   )r]   r[   rR   rC   re   rd   NN)r5   
__module____qualname____firstlineno____doc__r0   rj   r_   r\   r|   r   r   r   r   r   r   r   r   r   r   r   __static_attributes____classcell__r   s   @r   rO   rO   Z   sa     H$2"""B-(@=(.+30 0r   rO   c                   *    \ rS rSrSrS rS rS rSrg)r3      z`
Create a StructProxy suitable for accessing regular values
(e.g. LLVM values or alloca slots).
c                 "    UR                  5       $ rr   )get_value_typeru   s     r   r\   ValueStructProxy._get_be_type   s    ''))r   c                     U$ rr    ry   s      r   r|   &ValueStructProxy._cast_member_to_value       
r   c                     U$ rr   r   ry   s      r   r   (ValueStructProxy._cast_member_from_value   r   r   r   N	r5   r   r   r   r   r\   r|   r   r   r   r   r   r3   r3      s    *r   r3   c                   *    \ rS rSrSrS rS rS rSrg)r4      zG
Create a StructProxy suitable for accessing data persisted in memory.
c                 "    UR                  5       $ rr   )get_data_typeru   s     r   r\   DataStructProxy._get_be_type   s    &&((r   c                 p    U R                   R                  U5      nUR                  U R                  U5      $ rr   )rC   	get_model	from_datar[   rf   rz   r{   models       r   r|   %DataStructProxy._cast_member_to_value   s+    ))%0t}}c22r   c                 p    U R                   R                  U5      nUR                  U R                  U5      $ rr   )rC   r   as_datar[   r   s       r   r   'DataStructProxy._cast_member_from_value   s+    ))%0}}T]]C00r   r   Nr   r   r   r   r4   r4      s    )31r   r4   c                   l   ^  \ rS rSrSrSS jrS rS rS rU 4S jr	S r
S	 rS
 rS rS rS rSrU =r$ )	Structure   zg
A high-level object wrapping a alloca'ed LLVM structure, including
named fields and attribute access.
c                    UR                  U 5      U l        Xl        X l        Uc  [	        X R                  SS9U l        Ubn  [        UR                  5      (       a   eUR                  U R                  :X  d   UR                  U R                  45       eUR                  X0R
                  5        OUb   e[        UR                  5      (       d   eU R                  UR                  R                  :w  ab  U(       a*  UR                  X@R                  R                  5       5      nO1[        SUR                  R                  < SU R                  < 35      eX@l        0 U l        / U l        / U l        [!        S5      n[#        U R$                  5       HW  u  nu  pXpR                  U'   U R                  R'                  U[!        U5      45        U R                  R'                  U	5        MY     g )NTrm   zmismatching pointer type: got z, expected r   )get_struct_type_typerR   r[   ro   rd   r^   r   rc   r`   bitcastrb   rY   _namemap_fdmap_typemapint32_tr   rD   append)
rf   rg   r   r   rh   cast_refr<   r!   rL   tps
             r   rj   Structure.__init__  sx   ,,T2
;%gzzFDK %ejj1111zzTZZ/I%**djj1II/e[[1= =chh''''zzSXX---!//#zz/D/D/FGC#88++TZZ9: : Kqz#DLL1JAw MM!KKgaj12MM  $ 2r   c                 j    U R                   R                  U R                  U R                  U   SS9nU$ )NT)inbounds)r[   geprd   r   )rf   rz   r   s      r   r   Structure._get_ptr_by_index$  s/    mmT[[-?$O
r   c                 >    U R                  U R                  U   5      $ rr   )r   r   )rf   r   s     r   r   Structure._get_ptr_by_name(  s    %%dmmH&=>>r   c                 f    UR                  S5      (       d  X R                  U      $ [        U5      er   )r   r   r   r   s     r   r   Structure.__getattr__+  s2     $$e,-- ''r   c                 z   > UR                  S5      (       a  [        [        U ]  X5      $ X U R                  U   '   gr   )r   r   r   r   r   r   s      r   r   Structure.__setattr__4  s9     C  D5eCC%*T]]5!"r   c                 V    U R                   R                  U R                  U5      5      $ r   )r[   r   r   r   s     r   r   Structure.__getitem__<  s$    
 }}!!$"8"8"?@@r   c                 (   U R                  U5      nUR                  R                  UR                  :w  aB  Sn[        XA[	        UR                  R                  5      [	        UR                  5      4-  5      eU R
                  R                  X#5        g)r   z:Type mismatch: __setitem__(%d, ...) expected %r but got %rN)r   r   r`   ra   r6   r[   rc   )rf   rz   r   r   fmts        r   r   Structure.__setitem__C  sy     $$U+88uzz)NC (+CHH,<,<(=(+EJJ(9 "9 : : 	E'r   c                 ,    [        U R                  5      $ r   )r%   r   r   s    r   r   Structure.__len__O  s     4==!!r   c                     U R                   $ r   )rd   r   s    r   r   Structure._getpointerU  s     {{r   c                 L    U R                   R                  U R                  5      $ r   )r[   r   rd   r   s    r   r   Structure._getvalue[  s     }}!!$++..r   c                     [        UR                  5      (       a   eUR                  U R                  :X  d   UR                  U R                  45       eU R                  R	                  XR
                  5        g)z!Store the value in this structureN)r^   r   r   r[   rc   rd   r   s     r   r   Structure._setvaluea  sU    ejj))))zzTZZ'A%**djj)AA'E;;/r   )r[   rR   r   r   r   r   rd   )NNF)r5   r   r   r   r   rj   r   r   r   r   r   r   r   r   r   r   r   r   r   s   @r   r   r      sE    %>?(+A
("/0 0r   r   c                    [        U[        5      (       a  [        R                  " [        U5      n[
        R                  " U 5         U R                  5          U R                  XUS9nU R                  U" S5      U5        SSS5        U(       a+  U R                  WR                  R                  S5      U5        WsSSS5        $ ! , (       d  f       NK= f! , (       d  f       g= f)a  Allocate stack memory at the entry block of the current function
pointed by ``builder`` with llvm type ``ty``.  The optional ``size`` arg
set the number of element to allocate.  The default is 1.  The optional
``name`` arg set the symbol name inside the llvm IR for debugging.
If ``zfill`` is set, fill the memory with zeros at the current
use-site location.  Note that the memory is always zero-filled after the
``alloca`` at init-site (the entry block).
)sizenameN)rT   intr   r&   intp_tr	   suspend_emissiongoto_entry_blockallocarc   r   r`   )r   tyr  r  rn   r   s         r   ro   ro   j  s     ${{64( 
	#	#G	,%%'..T.:CMM"T(C( (
 MM#((**40#6 
-	,'' 
-	,s$   C)C;C
C	C
C%c                 t    U" S5      nUR                  [        S5      /5      nU R                  U[        5      $ )zCompute sizeof using GEP
    Nr
   )r   r   ptrtointr  )r   ptr_typenulloffsets       r   sizeofr    s4     D>DXXwqzl#FFF++r   c                 P    [        XR                  US9nU R                  X5        U$ )z
Like alloca_once(), but passing a *value* instead of a type.  The
type is inferred and the allocated slot is also initialized with the
given value.
rm   )ro   r   rc   )r   r   r  rn   storages        r   alloca_once_valuer    s%     '::U;GMM%!Nr   c                     [        XU5      nUR                  R                  S5        UR                  R                  S5        U$ )zS
Insert a pure function (in the functional programming sense) in the
given module.
readonlynounwind)get_or_insert_function
attributesaddmodulefntyr  fns       r   insert_pure_functionr    s9    
 
 d	3BMMj!MMj!Ir   c                 r    U R                   R                  US5      nUc  [        R                  " XU5      nU$ )za
Get the function named *name* with type *fnty* from *module*, or insert it
if it doesn't exist.
N)globalsr2   r   Functionr  s       r   r  r    s4    
 
		D$	'B	z[[t,Ir   c                 h     U R                  U5      $ ! [         a    U R                  U5      s $ f = frr   )get_named_metadataKeyErroradd_named_metadata)r  r  s     r   get_or_insert_named_metadatar&    s8    /((.. /((../s    11c                 R    U R                  U5      n[        R                  " XXC5      $ rr   )get_unique_namer   GlobalVariable)r  r
  r  r   unique_names        r   add_global_variabler+    s%    ((.KV@@r   c                 Z    U R                   nUR                  c  U R                  U5        g g rr   )basic_block
terminatorbranch)r   bbendbbs      r   	terminater2    s(    			B	}}u r   c                     U " S 5      $ rr   r   )ltypes    r   get_null_valuer5    s    ;r   c                 P    [        UR                  5      nU R                  SX!5      $ )N==r5  r   r   r   r{   r  s      r   is_nullr:    #    #((#D  t11r   c                 P    [        UR                  5      nU R                  SX!5      $ )Nr   r8  r9  s      r   is_not_nullr=    r;  r   c                 "    U R                  USS9$ )NFlikelyif_thenr   preds     r   if_unlikelyrE    s    ??4?..r   c                 "    U R                  USS9$ )NTr?  rA  rC  s     r   	if_likelyrG    s    ??4?--r   c                 B    U R                  U R                  U5      5      $ rr   )rB  not_rC  s     r   ifnotrJ    s    ??7<<-..r   c                 F    UR                  S5      nU R                  XS/S9$ )z
Increment an index *val*.
r
   nsw)flags)r   r  )r   r{   ones      r   increment_indexrO    s(     ((1+C ;;sw;//r   Loop)rz   do_breakc              #     ^ ^#    Uc  UR                   nUc  U" S5      nUnT R                  S5      nT R                  S5      nT R                  S5      mUU 4S jnT R                  nT R                  U5        T R	                  U5         T R                  USS9n	T R                  S	X5      n
T R                  XT5        SSS5        T R	                  U5         [        W	U5      v   T R                  n[        T U	5      n[        T U5        SSS5        W	R                  X(5        U	R                  WU5        T R                  T5        g! , (       d  f       N= f! , (       d  f       NT= f7f)
z
Generate LLVM IR for a for-loop in [start, count).
*start* is equal to 0 by default.

Yields a Loop namedtuple with the following members:
- `index` is the loop index's value
- `do_break` is a no-argument callable to break out of the loop
Nr   for.condfor.bodyfor.endc                  (   > TR                  T 5        g rr   )r/  )r0  r   s   r   rQ  for_range.<locals>.do_break  s    ur   
loop.indexr  <)r   append_basic_blockr-  r/  
goto_blockphiicmp_signedcbranchrP  rO  r2  add_incomingposition_at_end)r   countstartintpstopbbcondbbbodyrQ  bbstartrz   rD  incrr0  s   `           @r   	for_rangerj    s>     |zz}QD''
3F''
3F&&y1E !!GNN6			F	#D|4""34e, 
$
 
		F	#5(##$$w.'6" 
$ 
u&	tV$E" 
$	#
 
$	#s6   BE)	5E>E)3E
=E)
EE)
E&"E)c              #   ~  #    Uc  UR                   nU R                  S5      nU R                  S5      nU R                  S5      nU R                  n	U R                  U5        U R	                  U5         U R                  USS9n
U R                  USS9nU(       a  U R                  SX5      nOU R                  S	X5      nU R                  XU5        SSS5        U R	                  U5         W
W4v   U R                  nU R                  X5      n[        X5      n[        X5        SSS5        W
R                  X5        U
R                  WU5        WR                  [        R                  " US
5      U	5        UR                  WU5        U R                  U5        g! , (       d  f       N= f! , (       d  f       N= f7f)a  
Generate LLVM IR for a for-loop based on a slice.  Yields a
(index, count) tuple where `index` is the slice index's value
inside the loop, and `count` the iteration count.

Parameters
-------------
builder : object
    IRBuilder object
start : int
    The beginning value of the slice
stop : int
    The end value of the slice
step : int
    The step value of the slice
intp :
    The data type
inc : boolean, optional
    Signals whether the step is positive (True) or negative (False).

Returns
-----------
    None
NrS  rT  rU  rX  rY  z
loop.countrZ  >r   )r   r[  r-  r/  r\  r]  r^  r_  r  rO  r2  r`  r   r&   ra  )r   rc  re  steprd  incrf  rg  r0  rh  rz   rb  rD  ri  
next_counts                  r   for_range_slicerp    s|    4 |zz''
3F''
3F&&y1E!!GNN6			F	#D|4D|4&&sE8D&&sE8De, 
$ 
		F	#Ul$${{5'$W4
'" 
$ 
u&	tV$	r{{4+W5	z6*E") 
$	# 
$	#s8   A1F=3AFF=+:F,%A6F=
F)%F=,
F:6F=c           	   #   8  #    UR                   nU R                  SU[        R                  " US5      5      n[	        XX#USS9n[	        XX#USS9n[
        S 5       nU R                  USS9 u  pU" X5      U" X5      4v   SSS5        g! , (       d  f       g= f7f)	a  
A helper wrapper for for_range_slice().  This is a context manager which
yields two for_range_slice()-alike context managers, the first for
the positive step case, the second for the negative step case.

Use:
    with for_range_slice_generic(...) as (pos_range, neg_range):
        with pos_range as (idx, count):
            ...
        with neg_range as (idx, count):
            ...
>=r   T)rn  Fc              3      #    U    U nUv   S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f7frr   r   )condinner_cmr   s      r   cm_cond(for_range_slice_generic.<locals>.cm_cond`  s+     U  T Ts'   A //	A 
,	/
=A r?  N)r   r^  r   r&   rp  r   if_else)r   rc  re  rm  rd  is_pos_steppos_for_rangeneg_for_rangerv  then	otherwises              r   for_range_slice_genericr~  L  s      ::D%%dD"++dA2FGK#GD$OM#GD%PM 
 
T	26Gtd*GI,MMM 
3	2	2s   A)B+B	 	B	
BBc              #      #    US;   d   eU(       d  Sv   gUS:X  a  S nOS n[        X" U5      U5       n[        U5      [        U5      :X  d   eU" U5      v   SSS5        g! , (       d  f       g= f7f)a  
Generate a loop nest walking a N-dimensional array.
Yields a tuple of N indices for use in the inner loop body,
iterating over the *shape* space.

If *order* is 'C' (the default), indices are incremented inside-out
(i.e. (0,0), (0,1), (0,2), (1,0) etc.).
If *order* is 'F', they are incremented outside-in
(i.e. (0,0), (1,0), (2,0), (0,1) etc.).
This has performance implications when walking an array as it impacts
the spatial locality of memory accesses.
CFr   Fc                     U S S S2   $ )Nr   xs    r   <lambda>loop_nest.<locals>.<lambda>~  s    a"gr   c                     U $ rr   r   r  s    r   r  r    s    ar   N)
_loop_nestr%   )r   shaperd  order_swapindicess         r   	loop_nestr  j  si      D==C<%EEut4w<3u:---.  544s   4A5%A$	A5$
A2.A5c              #     #    [        XS   US9 n[        U5      S:  a+  [        XSS  U5       nUR                  4U-   v   S S S 5        OUR                  4v   S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f7f)Nr   rd  r
   )rj  r%   r  rz   )r   r  rd  loopr  s        r   r  r    sp     	7!H4	0Du:>G12Y5zzmg-- 65 ::- 
1	055 
1	0s3   BA4A#A4	B#
A1	-A44
B>Bc                     [        U5      nUc  US   R                  n[        R                  " X#5      " [        R                  5      n[        U5       H  u  pVU R                  XFU5      nM     U$ )z
Pack a sequence of values in a LLVM array.  *ty* should be given
if the array may be empty, in which case the type can't be inferred
from the values.
r   )r%   r   r   r'   r   r   r   )r   r   r
  r+   aryr!   r   s          r   
pack_arrayr    s^     	FA	zAY^^
,,r
bll
+C&!""31- "Jr   c                     [         R                  " U Vs/ s H  o"R                  PM     sn5      nU" [         R                  5      n[	        U5       H  u  pRU R                  XBU5      nM     U$ s  snf )z/
Pack a sequence of values into a LLVM struct.
r   )r   r   r   structtystr!   s         r   pack_structr    s`     ##V$<VVVV$<=H	",,	B&!!!"+ "I	 %=s   A/c                     Uc  [        UR                  R                  5      n[        U5       Vs/ s H  nU R	                  X5      PM     nnU$ s  snf )z@
Unpack an array or structure of values, return a Python tuple.
)r%   r   elementsrangeextract_value)r   tuprb  r!   valss        r   unpack_tupler    sV     }CHH%%&5\#! !!#)! 	 #K#s   Ac                     [        XR                  UR                  S9n[        XR                  UR                  S9n[	        XUR
                  UXR                  UXVS9	$ )N)rb  )r.   r  strideslayoutinds
wraparoundboundscheck)r  r  ndimr  get_item_pointer2r.   r  )	rg   r   arytyr  r  r  r  shapesr  s	            r   get_item_pointerr    sQ    
 '99EJJ?F7KKuzzBGWCHHF%,\\(2M Mr   c                   ^^^^ UUUU4S jnSnTR                  STT5      n[        TU5         [        R                  (       a  U" 5         U R                  R                  T[        U45        S S S 5        TR                  STTR                  S5      5      n[        TU5         [        R                  (       a  U" 5         U R                  R                  T[        U45        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f)Nc                     > T bC  [        T [        5      (       a  [        TSR                  T 5      TT5        g [        TSTT T5        g [        TSTT5        g )NzFdebug: IndexError: index %d is out of bounds for axis {} with size %d
zFdebug: IndexError: index %d is out of bounds for axis %d with size %d
z9debug: IndexError: index %d is out of bounds for size %d
)rT   r  printfrZ   )axisr   dimleninds   r   _dbgdo_boundscheck.<locals>._dbg  sb     $$$w !44:F4L#vO w !458$ 7O r   zindex is out of boundsrr  rZ  r   )r^  rE  r   FULL_TRACEBACKS	call_convreturn_user_exc
IndexErrorr   )	rg   r   r  r  r  r  msgout_of_bounds_upperout_of_bounds_lowers	    ````    r   do_boundscheckr    s         #C!--dC@	W1	2!!F))':vF 
3 "--c3D	W1	2!!F))':vF 
3	2 
3	2
 
3	2s   ?C,$?C=,
C:=
Dc	                    U(       al  / n	[        Xc5       HZ  u  pUR                  SXR                  S5      5      nUR                  X5      nUR	                  XU
5      nU	R                  U5        M\     OUn	U(       a-  [        [        X5      5       H  u  nu  p[        XXU5        M     U	(       d  UR                  U[        S5      /5      $ U	S   R                  nUS;   Ga  / nUS:X  aV  [        [        U5      5       H=  nU" S5      nUUS-   S   H  nUR                  UU5      nM     UR                  U5        M?     OdUS:X  aS  [        [        U5      5       H:  nU" S5      nUS U  H  nUR                  UU5      nM     UR                  U5        M<     O[        S5      eU" S5      n[        U	U5       H*  u  nnUR                  UU5      nUR                  UU5      nM,     UR                  UU/5      nU$ [        XI5       VVs/ s H  u  nnUR                  UU5      PM     nnn[        R                  " UR                  U5      n[!        XU5      $ s  snnf )NrZ  r   r  Cr
   r  unreachable)zipr^  r   r  selectr   r   r  r   r   r  r%   mul	Exception	functoolsreducepointer_add)rg   r   r.   r  r  r  r  r  r  r  r  r  negativewrappedselectedr  rd  stepsr!   lastjlocstmpr   dimoffsr  s                              r   r  r    s'   
 t+KC**3XXa[AHkk&.G~~h=HNN8$	 , #,S-@#AD-37S$? $B {{4'!*..1:??D~S=3u:&Awq1uvA";;tQ/D 'T"	 '
 s]3u:&AwrA";;tQ/D #T"	 ' M** 1g'DAq++a#C++c3'C ( kk$&
 25W1FG1FA7;;q!$1FG!!'++w77&11 Hs   
Ic                 V   UR                  S5      n[        UR                   [        R                  [        R                  45      (       a
  U" X5      nU$ [        UR                   [        R
                  5      (       a  U R                  X1U5      nU$ [        SUR                   < 35      e)Nr   zunexpected value type )r   rT   r   	FloatType
DoubleTyper(   r^  rY   )r   r   fpredicondnullvalisnulls         r   _scalar_pred_against_zeror    s    jjmG%**r||R]];<<u&
 M	 
EJJ

	+	+$$U7; M ejjBCCr   c                 Z    [        X[        R                  " U R                  S5      S5      $ )zC
Return a predicate representing whether *value* is equal to zero.
r7  r  r  partialfcmp_orderedr   s     r   is_scalar_zeror  %  s-     %	))'*>*>EtM Mr   c                 Z    [        X[        R                  " U R                  S5      S5      $ )z|
Return a predicate representing whether a *value* is not equal to zero.
(not exactly "not is_scalar_zero" because of nans)
r   r  r  r  fcmp_unorderedr   s     r   is_not_scalar_zeror  -  -    
 %	))'*@*@$GO Or   c                 Z    [        X[        R                  " U R                  S5      S5      $ )zQ
Return a predicate representing whether *value* is equal to either zero
or NaN.
r7  r  r   s     r   is_scalar_zero_or_nanr  6  r  r   c                 Z    [        X[        R                  " U R                  S5      S5      $ )z2
Is *value* negative?  Assumes *value* is signed.
rZ  r  r   s     r   is_scalar_negr  C  s-     %	))'*>*>DcK Kr   stackc              #      #    UR                  U R                  USS95      u  p4U   Sv   SSS5        UR                  U5        g! , (       d  f       N = f7f)ah  
The Python code::

    with contextlib.ExitStack() as stack:
        with early_exit_if(builder, stack, cond):
            cleanup()
        body()

emits the code::

    if (cond) {
        <cleanup>
    }
    else {
        <body>
    }

This can be useful for generating code with lots of early exits, without
having to increase the indentation each time.
Fr?  N)enter_contextrx  )r   r  rt  r|  r}  s        r   early_exit_ifr  K  sF     , ))'//$u/*MNOD	 
		" 
s   $AAA
AAc                 ,    [        X[        X5      5      $ )z
A convenience wrapper for :func:`early_exit_if`, for the common case where
the CPython API indicates an error by returning ``NULL``.
)r  r:  )r   r  objs      r   early_exit_if_nullr  g  s    
 )>??r   c                     UR                  [        X5      SS9   US   nUSS =(       d    SnU R                  R                  XU5        SSS5        g! , (       d  f       g= f)zi
Guard against *value* being null or zero.
*exc_tuple* should be a (exception type, arguments...) tuple.
Fr?  r   r
   N)rB  r  r  r  )rg   r   r   	exc_tupleexcexc_argss         r   
guard_nullr  o  sU    
 
7	FlQR=(D))'A 
G	F	Fs   0A
A!c                 8   [        UR                  [        R                  5      (       d   UR                  5       eU(       a  U4OSnUR	                  [        X5      SS9   U R                  R                  U[        U5        SSS5        g! , (       d  f       g= f)z?
Guard against *pointer* being NULL (and raise a MemoryError).
r   Fr?  N)	rT   r   r   PointerTyperB  r:  r  r  MemoryError)rg   r   pointerr  r  s        r   guard_memory_errorr  z  sm     gllBNN33AW\\A3v"H	25	A))';I 
B	A	As    "B
Bc              #   z   #    U R                  [        X5      US9   Sv   SSS5        g! , (       d  f       g= f7f)z6
Execute the given block if the scalar value is zero.
r?  N)rB  r  )r   r   r@  s      r   if_zeror    s+     
 
7	G 
H	G	Gs   ;*	;
8;c                 6    [        U [        R                  5      $ )z/
Whether the LLVM type *typ* is a struct type.
)rT   r   r  )ltyps    r   r^   r^     s     dBNN++r   c                     [        XSU5      n[        UR                  R                  5      (       a   eU R	                  XCR                  5       5      $ r   )r   r^   r   r`   r   rb   )r   recordr  typpvals        r   get_record_memberr    sA    F3D$))++,,,,??4!122r   c                 D    U R                  SXR                  S5      5      $ )NrZ  r   )r^  r   )r   r{   s     r   
is_neg_intr     s    sC!55r   c                 $    [        X/UQ7SS0UD6$ )z0
Same as *gep*, but add the `inbounds` keyword.
r   T)r   )r   r   r  kwss       r   r   r     s     w9d9T9S99r   c                     UR                  SS5      nUR                  SS5      nU(       a   e/ nU H7  n[        U[        5      (       a  [        U5      nOUnUR	                  U5        M9     U R                  XXES9$ )z}
Emit a getelementptr instruction for the given pointer and indices.
The indices can be LLVM values or Python int constants.
r   r   F)r  r   )rE   rT   r  r   r   r   )	r   r   r  r  r  r   idxr!   r  s	            r   r   r     su    
 7762Dwwz5)HN7
Ca!*CC

3  ;;sd;>>r   c                     U R                  U[        5      n[        U[        5      (       a  [        U5      nU R	                  XB5      nU R                  XC=(       d    UR                  5      $ )z
Add an integral *offset* to pointer *ptr*, and return a pointer
of *return_type* (or, if omitted, the same type as *ptr*).

Note the computation is done in bytes, and ignores the width of
the pointed item type.
)r  r  rT   r  r  inttoptrr   )r   r   r  return_typeintptrs        r   r  r    sT     c6*F&#[[(FF$;388<<r   c           	         U R                   R                  S[        UR                  45      nU R	                  U[        5      n[        U[        5      (       a  [        U5      nU R                  XAX2[        S5      /5        g)z5
Fill *size* bytes starting from *ptr* with *value*.
zllvm.memsetr   N)
r  declare_intrinsic	voidptr_tr   r   rT   r  int8_tcallbool_t)r   r   r  r   r  s        r   memsetr    s`     
	)	)-)TYY9O	PB
//#y
)C%uLL5q	23r   c                     U R                  U5      n[        X[        XR                  5      S5        U R	                  X!5        g)z/
Fill padding bytes of the pointee with zeros.
r   N)r   r  r  r   rc   )r   r   r{   s      r   memset_paddingr    s3    
 ,,s
C
72A6MM#r   c                     [        U [        R                  5      (       a  U nOU R                  n[	        XBR
                  U5      nX5l        SUl        X%l        U$ )zG
Get or create a (LLVM module-)global constant with *name* or *value*.
T)	rT   r   Moduler  r+  r   linkageglobal_constantinitializer)builder_or_moduler  r   r  r  r.   s         r   r  r    sN     #RYY//""))vzz48DLDKr   c                    US:  d   eUR                  U5      nUR                  S5      n[        XR                   5      nU R                  [        X5      5       u  pVU   U R	                  X5      nU R                  Xt5        SSS5        U   U R                  X5      nU R	                  X5      nU R                  U R                  Xs5      U5        SSS5        SSS5        U R                  U5      nU R                  XR                  Xr5      5      n	Xy4$ ! , (       d  f       N= f! , (       d  f       N[= f! , (       d  f       Nd= f)z
Compute the (quotient, remainder) of *val* divided by the constant
positive *divisor*.  The semantics reflects those of Python integer
floor division, rather than C's / LLVM's signed division and modulo.
The difference lies with a negative *val*.
r   r
   N)
r   ro   rx  r   sdivrc   r  subr   r  )
r   r{   divisorrN  quotif_negif_posquot_valval_plus_onerem_vals
             r   divmod_by_constantr#    s     Q;;hhwG
((1+Cw)D	G1	26Fv||C1HMM()  ";;s0L||L:HMM'++h4d;	  
3 ||D!Hkk#{{8=>G V V 
3	2s=   D6#D
D6AD%D6
D"	D6%
D3	/D66
Ec                 n    U R                  S5      nU R                  XU5        U R                  U5        U$ )zy
Branch conditionally or continue.

Note: a new block is created and builder is moved to the end of the new
      block.
z	.continue)r[  r_  ra  )r   rt  bbtruebbconts       r   cbranch_or_continuer'    s5     ''4FOOD&)F#Mr   c                 J   UR                   UR                   :X  d   e[        XUR                   S9 nU R                  XR                  /5      nU R                  X$R                  /5      nU R	                  U R                  U5      U5        SSS5        g! , (       d  f       g= f)z
Emit a memcpy to the builder.

Copies each element of dst to src. Unlike the C equivalent, each element
can be any LLVM type.

Assumes
-------
* dst.type == src.type
* count is positive
r  N)r   rj  r   rz   rc   r   )r   rI   rJ   rb  r  out_ptrin_ptrs          r   memcpyr+    su     88sxx	7

	3t++cJJ<0S::,/gll6*G4 
4	3	3s   AB
B"c           	      d   UR                   n[        U[        5      (       a  [        R                  " Xu5      nU R
                  R                  U[        [        U/5      n[        n	U R                  XR                  U[        5      U R                  U[        5      U R                  XE5      U	/5        g rr   )r   rT   r  r   r&   r  r  r  	false_bitr  r   r  )
r   	func_namerI   rJ   rb  itemsizealignsize_tr+  is_volatiles
             r   _raw_memcpyr3  1  s    ZZF(C  ;;v0^^--i/8)V.LNFKLL//#y9!//#y9!++e6%' (r   c           	           [        U SXX4U5      $ )zU
Emit a raw memcpy() call for `count` items of size `itemsize`
from `src` to `dest`.
zllvm.memcpyr3  r   rI   rJ   rb  r/  r0  s         r   
raw_memcpyr7  ?  s    
 ws%PPr   c           	           [        U SXUXE5      $ )zV
Emit a raw memmove() call for `count` items of size `itemsize`
from `src` to `dest`.
zllvm.memmover5  r6  s         r   raw_memmover9  G  s    
 w%( (r   c                     U R                  X5      nU R                  US5      nU R                  US5      nU R                  XS5      nU R                  US5      nU R                  X`R                  US5      5      n	X4$ )ze
Compute (a * b + c) and return a (result, overflow bit) pair.
The operands must be signed integers.
r   r
   )smul_with_overflowr  sadd_with_overflowor_)
r   ar*   cpprodprod_ovfr  r;   ovfs
             r   muladd_with_overflowrD  P  s|    
 	""1(A  A&D$$Q*H""4+A


1
%C
++h 5 5a ;
<C8Or   c                    [        U[        5      (       d   eU R                  n[        n[	        US-   R                  S5      5      n[        USU5      n[        R                  " [        U/SS9n UR                  S5      nU R                  Xd5      n	U R                  X/[        U5      -   5      $ ! [         a    [        R                  " X7SS9n NPf = f)a   
Calls printf().
Argument `format` is expected to be a Python string.
Values to be printed are listed in `args`.

Note: There is no checking to ensure there is correct number of values
in `args` and there type matches the declaration in the format string.
 asciiprintf_formatTvar_argr  rY  )rT   r6   r  r  r,   encoder  r   FunctionTyper   
get_globalr$  r!  r   r  list)
r   rZ   argsmodcstring	fmt_bytes
global_fmtr  r  ptr_fmts
             r   r  r  ^  s     fc""""
..CG66w?@I oyAJ??7WIt<D3^^H% ooj2G<<IT
233	  3[[23s   0B0 0CCc                    [        U[        5      (       d   eU R                  n[        n[	        US-   R                  S5      5      n[        USU5      n[        R                  " [        U[        U/SS9n	Sn
[        R                  (       a  SU
-   n
 UR                  U
5      nU R!                  X5      nU R#                  XX,/[%        U5      -   5      $ ! [         a    [        R                  " XYU
S9n NQf = f)	z8Calls libc snprintf(buffer, bufsz, format, ...args)
    rF  rG  snprintf_formatTrI  snprintfr/   rY  )rT   r6   r  r  r,   rK  r  r   rL  r   r  r   IS_WIN32rM  r$  r!  r   r  rN  )r   bufferbufszrZ   rO  rP  rQ  rR  rS  r  symbolr  rT  s                r   rW  rW  x  s     fc""""
..CG66w?@I &7CJ??'67+TD Fv1^^F# ooj2G<<U4tDzABB	  1[[01s   C C54C5c                     [        U[        5      (       d   e[        R                  " [        R                  " S5      U5      n[        XSS9nU R                  U[        5      n[        X[        U5      U/UQ76   U$ )zoSimilar to `snprintf()` but the buffer is stack allocated to size
*bufsz*.

Returns the buffer pointer as i8*.
r   Trm   )
rT   r  r   r'   r(   ro   r   r  rW  r  )r   rZ  rZ   rO  spacetyspacerY  s          r   snprintf_stackbufferr_    se     eS!!!!ll2::a=%0G5E__UI.FWfUmV;d;Mr   c                 B    U R                  S5      R                  S5      $ )z_
Normalize the given string to latin1 compatible encoding that is
suitable for use in LLVM IR.
utf8latin1)rK  decode)texts    r   normalize_ir_textre    s     ;;v%%h//r   c                 ~   SnU R                  U[        5      n[        U SX5        [        R                  " S5      nU R                  XR                  5       5      n[        X5       nU R                  UR                  [        U5      5      nU R                  SU[        S5      5      nU R                  U5         [        U S5        SSS5        U R                  XR                  /5      nU R                  U5      n	[        U SU	5        SSS5        [        U S5        g! , (       d  f       N]= f! , (       d  f       N,= f)	zADebug print the memory region in *ptr* to *ptr + nbytes*
as hex.
   zhexdump p=%p n=%zur   r7  r   
Nz %02x)zextr  r  r   r(   r   rb   rj  uremrz   r   rB  r   r   )
r   r   nbytesbytes_per_linebyte_tr  div_bydo_new_liner  r{   s
             r   hexdumprp    s     N\\&&)F
7(ZZ]F
//#002
3C	7	#scii)?@++D&&)D__[)7D! * S99+.ll6"w% 
$ 7D *) 
$	#s&   &AD.9DAD.
D+	'D..
D<c                     U SL =(       d;    [        U [        R                  5      =(       d    [        U [        R                  5      $ )zreturns if 'ty' is none N)rT   r   NoneTypeOmittedr
  s    r   is_nonelikeru    s6     	d
 	&2u~~&	&2u}}%r   c                 t    [        U [        R                  5      =(       a    [        U R                  5      S:H  $ )z"returns if 'ty' is an empty tuple r   )rT   r   Tupler%   rt  s    r   is_empty_tuplerx    s,     	2u{{# 	BHHr   c                 l    [         R                  " [         R                  " U [        U5      5      U5      $ )zu
Create an LLVM-constant of a fixed-length array from Python values.

The type provided is the type of the elements.
)r   r&   r'   r%   )r
  r{   s     r   create_constant_arrayrz    s$     ;;r||BC1377r   rr   )r   )Nr  F)r  F)r   r   )NT)r  )FF)F)internal)r
   )gr   collections
contextlibr   r   r  llvmliter   
numba.corer   r   r   r	   numba.core.datamodelrU   r(   r  r  r   MACHINE_BITSr  rb   r  true_bitr-  	true_byte
false_byter   r"   r,   r1   r@   rM   objectrO   r3   r4   r   ro   r  r  r  r  r&  r+  r2  r5  r:  r=  rE  rG  rJ  rO  
namedtuplerP  rj  rp  r~  r  r  r  r  r  r  r  r  r  r  r  r  is_trueis_falser  r  r  r  r  r  
guard_zeror^   r  r   r   r   r  r  r  r  r#  r'  r+  r3  r7  r9  rD  r  rW  r_  re  rp  ru  rx  rz  r   r   r   <module>r     s  
  0   6 6  
A	A
**R.	E&&	'	!91I	1I	AY
=	:  &  " B06 B0J| 1l 1 g0 g0X2,/A
2
2
/./0 f&;< (# (#V 6# 6#r N N: ! !6    	 EJ!&	MG> 5:72tMOO K #) # #6@BJ   
,36:?&=4	>
5*(Q(44C40.8r   