
    pidV                    J   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Zd dl	Z
d dlZd dlmZ d dlmZmZmZmZmZmZ d dlmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' d dl(m)Z) d dlm*Z* d dl+m,Z, d d	l-m.Z.m/Z/m0Z0m1Z1 d d
l2m3Z3  G d de*jh                        Z5d Z6d Z7 edg dd      Z8d Z9 G d de1      Z:d Z;d Z<d Z=d Z>d Z?d Z@d ZAd ZBd ZCd ZDd  ZEd! ZFd" ZGd# ZHd$ ZId% ZJd& ZKd' ZLd( ZMd) ZNd* ZOd+ ZPd, ZQd- ZRd. ZSd/ ZTd0 ZUd1 ZVd2 ZWd3 ZXd4 ZYd5 ZZd6 Z[y)7    N)make_dataclass)parfor)typesirconfigcompilersigutilscgutils)add_offset_to_labelsreplace_var_namesremove_delslegalize_namesrename_labelsget_name_var_tablevisit_vars_innerget_definitionguardget_call_tableis_pureget_np_ufunc_typget_unused_var_nameis_const_callfixup_var_define_in_scopetransfer_scopefind_max_labelget_global_func_typfind_topo_order)	signature)lowering)ensure_parallel_support)NumbaParallelSafetyWarningNotDefinedErrorCompilerErrorInternalError)ParforLoweringBuilderc                   2     e Zd ZdZ fdZed        Z xZS )ParforLowerzlThis is a custom lowering class that extends standard lowering so as
    to accommodate parfor.Parfor nodes.c                 r    t        |t        j                        rt        | |       y t        |   |       y N)
isinstancer   Parfor_lower_parfor_parallelsuper
lower_instselfinst	__class__s     _/opt/services/ai/voice_agent/venv/lib/python3.12/site-packages/numba/parfors/parfor_lowering.pyr.   zParforLower.lower_inst2   s(    dFMM*"4.Gt$    c                      y)z
        Force disable this because Parfor use-defs is incompatible---it only
        considers use-defs in blocks that must be executing.
        See https://github.com/numba/numba/commit/017e2ff9db87fc34149b49dd5367ecbf0bb45268
        T )r0   s    r3   _disable_sroa_like_optz"ParforLower._disable_sroa_like_opt8   s     r4   )__name__
__module____qualname____doc__r.   propertyr7   __classcell__r2   s   @r3   r'   r'   -   s!    +%  r4   r'   c                 X    |j                   t        | |      S  |j                   | |      S r)   )lowerer_lower_parfor_parallel_std)r@   r   s     r3   r,   r,   B   s,    ~~)'6::v~~gv..r4   c                    ddl m} t                | j                  j                  }| j                  }| j
                  }| j                  j                  }t        j                  |      | j                  _        t        j                  r*t        d| j                  t        | j                               | j                  j                  }| j                  }t        j                  rt        d        |j                          |j                  j                   }	|j                  j"                  }
t        j                  r+t        d|j                  dt        |j                               |j                  j$                  D ]/  }t        j                  rt        d|       | j'                  |       1 |j(                  D ]?  }||vs||   }t+        j,                  |
||	      }| j/                  |j0                  |       A i }i }t2        j4                  j6                  j9                  ||j:                  || j<                  ||       t        j                  rt        d|       t        d	|       |j:                  J t2        j4                  j6                  j?                  ||j:                        }|j@                  |jB                  }}t        j                  rt        d|       t        d|       tE        |      }i }g }|dkD  r|j                  j"                  }
|j                  j                   }	tG        | |
|	      }|jI                  t2        jJ                  jL                  jN                  jP                  tS        t2        jJ                  jL                  jN                  jP                        d      }|jU                  |jW                  |g       tX        jZ                  d      }t]        |      D ]  }||   }| j                  j                  |   }t+        j,                  |
||	      }t_        |      }|j`                  }t        j                  r.t        d||||tY        jb                  |      |t        |             te        |tX        jf                  jh                        r|jj                  dz   } nd} |jI                  tJ        jl                  to        tJ        jl                  |jp                        tY        jr                  tX        jZ                  |       fdtY        jb                  |      i      }!|g}"te        |tX        jf                  jh                        r|jU                  t*        jt                  jw                  |d|	      tY        jr                  tX        jZ                  |jj                        d      }#t]        |jj                        D ]U  }$|jU                  t*        jt                  jy                  |#|$d
|	      tX        jZ                  d      }%|"j{                  |%       W |j}                  |"d      }&|jp                  j                  |      }'|j                  |'tY        jb                  |            }(|jW                  |!|&|(g      })|jU                  |)|d      }*|*||j0                  <   |j{                  |*       ||   j                  }+|+te        |tX        jf                  jh                        r|jI                  tJ        j                  to        tJ        j                  |jp                        tY        jr                  tX        jZ                  |jj                        |fdtY        jb                  |      i      },|j                  |+|d      }-|jW                  |,#|-|(g      }.|jU                  |.|d       }/|j{                  |/       n|j                  |+|d       }/n|}/t        j                  rd!t        |      z   d"z   }0tY        j                  |0      }1|j                  |0|1d#      }2t+        j                  |2|gd
|	$      }3t        tX        j                  ||2j0                     ||j0                           | j                  j                  |3<   t        d%|3       | j'                  |3       ||j0                     }4|j                  |4      }5t        j                  ||5      }6|
j                  d&|	      }7|4||7j0                  <   |6| j                  |7j0                  <   t        j                  || j                  |j0                        |5'      5 }8|j                  |8j                  |6       |j                  |*|7|/(       d
d
d
        |j                  j                         }9d)|9_T        ||j                  d   j                  j0                     }:|j                  dd
 D ]   };||;j                  j0                     |:k(  r J  d*t2        j4                  j6                  _W        	 t        | |||||9i t        |      |:|j(                  
      \  }<}=}>}?}@d+t2        j4                  j6                  _W        d,g|=z   }=tE        |      }AtE        |=      tE        |      z
  |Az
  }Bt        j                  r<t        d-|=       t        d.B       t        d/|       t        d0|       t        d1A       t        |j                  BA|=|>|j(                  |      }Ct        j                  rt        d2C       |j                  D ;cg c]%  };|;j                  |;j                  |;j                  f' }D};t        j                  r"t        d3|j                         t        d4D       t        | |<C|>|=|?D||||j                  |:|j(                  @       |dkD  rt        ||| |       |D ]2  }E| j'                  t+        j                  |Ej0                  |	5             4 || j                  _        t        j                  rt        d6       y
y
# 1 sw Y   XxY w# d+t2        j4                  j6                  _W        w xY wc c};w )7a  Lowerer that handles LLVM code generation for parfor.
    This function lowers a parfor IR node to LLVM.
    The general approach is as follows:
    1) The code from the parfor's init block is lowered normally
       in the context of the current function.
    2) The body of the parfor is transformed into a gufunc function.
    3) Code is inserted into the main function that calls do_scheduling
       to divide the iteration space for each thread, allocates
       reduction arrays, calls the gufunc function, and then invokes
       the reduction function across the reduction arrays to produce
       the final reduction values.
    r   )get_thread_countzlowerer.fndescr,   zinit_block =  zlower init_block instr = 	alias_maparg_aliasesNzparfor_redvars:zparfor_reddict:)r@   scopelocr6   )fobjftypeargs)rK   num_threads_var)rhstypnamereduction_info   dtype)rI   rJ   rK   kwsshaperedarr_shaperedshapeonedimtuple_size_varrO   )cvalrN   redarrinit_val)rY   rN   rO   redtosetzres_print1 for redvar :	str_constrK   varargrH   res_print_redvarz$loop_index)intp)objindexvalnumpyTFschedzfunc_args = znum_inputs = parfor_outputs = parfor_redvars = znum_reductions = zgu_signature = zloop_nests = loop_ranges = )rH   z_lower_parfor_parallel done)bnumba.np.ufunc.parallelrC   r    contexttyping_contextbuilderfndesctypemapcopyr   DEBUG_ARRAY_OPTprinttypevarmapdump
init_blockrH   rG   bodyr.   racesr   Var_alloca_varrO   numbaparforsr   find_potential_aliases_parforparamsfunc_irget_parfor_outputsredvarsreddictlenr%   bind_global_functionnpufuncparallel_iget_num_threadsr   assigncallr   rb   rangeredtyp_to_redarraytyperR   DTyper*   npytypesArrayndimemptyr   
_typingctxUniTupleExprgetattrstatic_getitemappendmake_tuple_variableresolve_value_typemake_const_variabler[   fullDEBUG_ARRAY_OPT_RUNTIMEstrStringLiteralPrintr   none	calltypesget_value_typer
   alloca_onceredefine	for_rangeloadvarstorerd   setitemflagserror_model
loop_nestsindex_variablesequential_parfor_lowering_create_gufunc_for_parfor_bodybool_create_shape_signatureget_shape_classesstartstopstepcall_parallel_gufunc#_parfor_lowering_finalize_reductionDel)Fr@   r   rC   	typingctx	targetctxrn   orig_typemaprp   ru   rH   rG   instrracevarrvtyprvrE   rF   parfor_output_arraysparfor_redvarsparfor_reddictnredvarsredarrs
to_cleanuppfbdrget_num_threadsrL   ired_name
redvar_typredvarredarrvar_typreddtype	redarrdimglbl_np_emptysize_var_listredshape_varj	onedimvarsize_varrY   dt
empty_call
redarr_varr[   full_func_nodeinit_val_var	full_callr\   res_print_strstrconsttyplhs	res_printnum_thread_typentllvm_typealloc_loop_varnumba_ir_loop_index_varloopr   index_var_typlfunc	func_argsfunc_sigfunc_arg_typesexp_name_to_tuple_varnum_reductions
num_inputsgu_signatureloop_rangesvsF                                                                         r3   rA   rA   I   s
    9..IIooG >>))L!YY|4GNNW^^0DEnn$$G^^F&'




C##E ov00#tF<M<M7NO""'' "!!-u55!"
 << 0& G$Ew,B/	0 IK	MM66vv}}g(/KQk9%m[) ==$$$ ==//BB%+^^V^^NN00 >"HGJ!|!!''##%gUL  44((::%ehhnn&=&=&O&OP 5 
  ,,

?
4

" ' $ x h	[A%a(H //9JVVE8S1F 3:>M$**H%%$!KK)#)	 *enn&:&:;&OOa/		
 "66XX&rxx1A1ABNN5::y9 ekk(34 7 M --M *enn&:&:;$||=uzz:??C'  ,   z/ 4A %GG22<D#N!JJ- !- !I
 "((34 00$4 1 H
 ##66x@D**%++h:O*PBM2GJM & J
 $.GFKK j)%h/88H#j%..*>*>? &+%?%?WW.rww8H8HI!NN5::zG$ %ekk(&;< &@ &N $)#<#<%$' $= $L !&

&lL"-M !+ !I  %||%&'  ,  H %%h/$88%$'  9  H "11$<s6{$JS$PM"'"5"5m"DK33*'( 4 C !#sFm04#!?I:CEJJ=DSXX=N=DV[[=Q;SGNN,,Y7 ,i8&&y1 &o&:&:;O#22?CK$00+FN ',nn]C&H#4CG+001 <JGNN2778 ""7GOOO<P<P,QXcd [hldjj.9 *4KQYZ[ [Gh	[V LLEEF--a0??DDEMqr" ?q'',,->>>?6:EMM3	@
 #AVWiE2O]FLL#:		 				 ;@7 	I%I(NY#&:";;nLJni(oz*!#78!>2!>2*  L . 7=6G6GHAGGQVVQVV,HKHov001,  !|+GWno	

  4266!&&c234 *GNN+, c[ [2 ;@70 Is   1p>)-q ;*q/>q	!q,_ReductionInforedvar_inforedvar_namer   r   
redarr_typr[   T)frozenc           	      P   |j                         D ]  \  }}|j                  j                  |   }|j                  j                  |j                     }|j	                  |      }	t        ||   |||||	      }
|
j                  j                  t        nt        } || |||
        y)zYEmit code to finalize the reduction from the intermediate values of
    each thread.
    r   N)
itemsro   rp   rO   r   r   r   redop_lower_trivial_inplace_binops_lower_non_trivial_reduce)r   r   r@   r   thread_count_varr   r   r   r   r[   reduce_infohandlers               r3   r   r     s     $+==? @Z ^^++K8
^^++JOO<
??;/$(5#!!!
 "--33? 11 	 	!1;?-@r4   c                        e Zd Z fdZ xZS ) ParforsUnexpectedReduceNodeErrorc                 *    t         |   d|        y )Nz!Unknown reduce instruction node: )r-   __init__r/   s     r3   r  z)ParforsUnexpectedReduceNodeError.__init__  s    <TFCDr4   )r8   r9   r:   r  r=   r>   s   @r3   r   r     s    E Er4   r   c                    |j                   j                  D ]  }t        ||      rnt        ||j                  d      rL|j
                  j                  }t        ||||      }|j                  ||j                  j                         nnt        ||j                  d      rL|j
                  j                  }t        ||||      }|j                  ||j                  j                         nt        |      t        | |||j                        s n t        j                  r<|j                  }|j                  | j                    dj"                   d| d|       yy)z+Lower trivial inplace-binop reduction.
    inplace_binoprX   binopz	: parfor z reduction  =N)r   reduce_nodes_lower_var_to_var_assign_is_right_op_and_rhs_is_initr   valuefn_emit_binop_reduce_callstorevartargetrO   r   _fix_redvar_name_ssa_mismatchr   r   print_variablerH   r8   )r   r@   r   r   r1   r
  redvar_resultvarnames           r3   r   r     sC    ''44 #GT2)$0G0GYB3G-{M ]1A1AB)$0G0GQB3G-{M ]1A1AB 3488 )$#.#:#:<34 %%))zzl)BKK=G9BG	
 &r4   c                 .  
 |j                    d
|j                  j                  j                  
|j                         |j                  |j                        }t        j                  |j                  |      5 }|j                  }|j                  j                  D ]  }t        ||      rnxt        |t        j                         rSt#        
fd|j%                         D              r1t'        |||      }|j)                  |
       |j+                  |       nt-        |      t/        | |||j                         s n ddd       t0        j2                  r/|j                   }	|j5                  | j6                   d|	 d|	       yy# 1 sw Y   IxY w)zFLower non-trivial reduction such as call to `functools.reduce()`.
    #initc              3   <   K   | ]  }|j                   k(    y wr)   rX   ).0var	init_names     r3   	<genexpr>z,_lower_non_trivial_reduce.<locals>.<genexpr>  s     NcCHH	1Ns   Nz: parfor non-trivial reduction r  )r   ro   rp   
setdefaultr   r   rO   r
   r   rn   rd   r   r  r  r*   r   Assignany	list_vars_emit_getitem_callr  r.   r   r  r   r   r  rH   )r   r@   r   r   num_thread_llvalr   tidr1   elemr  r  s             @r3   r   r     sg    **+51INN%%i1G1GH '7'<'<=			7??,<	= jj++88 	D'6T299-NT^^=MNN)#wD  y1""4( 7t<< -VWd'2'>'>@%	, %%))zzl9'"E	
 &- s   <CF FFc                    t        |t        j                        rqt        |j                  t        j                        rM| j                  |j                  j                        }| j                  ||j                  j                         yy)zaLower Var->Var assignment.

    Returns True if-and-only-if `inst` is a Var->Var assignment.
    rX   TF)	r*   r   r  r	  rz   r   rO   r  r  )r@   r1   loadeds      r3   r  r     s\    
 $		"z$**bff'E1dkk&6&67r4   c                    d }|j                   }|j                  }|j                  }|j                  |j                  j
                        }|| f}t        |j                  |t        j                        }	|j                  |||	|      }
|
S )z%Emit call to ``redarr_var[idx]``
    c                     | |   S r)   r6   )rZ   rd   s     r3   reducer_getitemz+_emit_getitem_call.<locals>.reducer_getitem.  s    e}r4   )rn   rl   r   r   r   rO   r   r   r   rb   compile_internal)idxr@   r   r%  rn   ctxr   arg_arrrK   sigr   s              r3   r  r  +  s|     ooG
//C''Jook4499:GS>D
K**J


CC#tDDKr4   c                    d }d }t         j                  |t         j                  |t         j                  |t         j                  |t         j
                  |t         j                  |t         j                  |t         j                  |t         j                  |t         j                  |i
|    }|j                  }|j                  }|j                  }	|j                  |j                  j                         }
t"        j$                  r|j                  j&                  j)                  |j*                        }t-        j.                  |j                  |gd|j0                        }|j2                  j4                  }t7        t8        j:                  ||j                  j                      ||j                            |j2                  j<                  |<   |j?                  |       |j                  |j                         }||
|j@                  f}t7        |jB                  t8        jD                  |	|jB                        }|jG                  ||||      }|S )z;Emit call to the ``binop`` for the reduction variable.
    c                 :    |}t        |       D ]
  }|||   z  } |S r)   r   thread_countrZ   initcr   s        r3   reduction_addz._emit_binop_reduce_call.<locals>.reduction_add?  -    |$ 	ANA	r4   c                 :    |}t        |       D ]
  }|||   z  } |S r)   r-  r.  s        r3   reduction_mulz._emit_binop_reduce_call.<locals>.reduction_mulE  r3  r4   Nr_   )$operatoriaddisubaddsubimul	ifloordivitruedivmulfloordivtruedivrl   rn   r   r   r   rO   r   r   rG   getr   r   r   rH   ro   rp   r   r   r   r   r.   r[   r   uintpr&  )r  r@   r   r   r2  r5  kernelr(  rn   r   r)  init_varr   rp   arg_thread_countrK   r*  r  s                     r3   r  r  ;  s    	}}mm}M=m=- F //CooG''Jook4499:G%%))//33K4K4KLHH(((3D
	 ..((.7JJ 6 6 ; ;<HMM"/
  + 	9%'7'<'<=g{';';<D
Z9O9OC ((&#tDMr4   c                     t        | t        j                        sy| j                  }t        |t        j                        sy|j
                  |k7  ry|j                  j                  | dk7  ryy)zDIs ``inst`` an inplace-binop and the RHS is the reduction init?
    Fr  T)r*   r   r  r	  r   oprM   rO   )r1   r   rG  rM   s       r3   r  r  t  sZ     dBII&
**Cc277#
vv|
ww||+e,,r4   c                    | j                   j                  }t        |t        j                        r	 |j                  |      }|j                  }|j                  j                  }||k(  }|rR||j                  j                  k7  r9|j                  |j                  j                        }	|j                  |	|       yy# t        $ r ||j                  j                  k(  }Y yw xY w)z5Fix reduction variable name mismatch due to SSA.
    rX   TF)rw   rG   r*   r   r  	get_exactunversioned_namer  r"   rO   r   r  )
r   r@   r1   r   rG   reduction_varredvar_unver_nametarget_unver_nameis_same_source_varre   s
             r3   r  r    s     ##E$		"	H!OOK8M !. > > $ < <!26G!G dkk...oodkk&6&67  ; 7+  	A "-0@0@!@		As   B? ?"C$#C$c                    t         j                  r8t        d||||       |dd D ]!  }t        d|t        |       | ||             # t	        |      |z
  }|dd D 	cg c]  }	|	|vr
 | |	|      nd }
}	t               }|
D ]  }|s|D ]  }|j                  |         |rt        |      dz   nd}|
j                  d|f       |j                  |       |dz   }|j                  |       i t        d      }|D ]  }|dk\  s	t        |      |<   |dz  } t        |      }d	|ifd
g }g }d}d}t         j                  r$t        d|       t        d|
       t        d|       t        |
|      D ]j  \  }}|dz   }|rt        fd|D              }nd}||kD  r+|j                  t        |gt        |dd       z                U|j                  |       ||z  }l ||fS c c}	w )z&Create shape signature for GUFunc
    r   rQ   Nargument)rp   )r   alatest_alphac                 N    | dk\  r||    S dxx   dz  cc<   t        d         S )Nr   rS  rQ   )chr)r1  	class_map
alpha_dicts     r3   
bump_alphaz+_create_shape_signature.<locals>.bump_alpha  s4    6Q<~&!+&z.122r4   r6   rK   classesthreadcount_ordinalc              3   0   K   | ]  } |        y wr)   r6   )r  r1  rX  rV  s     r3   r  z*_create_shape_signature.<locals>.<genexpr>  s     C!Z95Cs   )r   rr   rs   rt   r   setr9  maxinsertordrU  ziptupler   list)r   r   r   rK   r   ry   rp   r   
num_inoutsr  rY  	class_set_class	max_classthread_num_classalphabetnrZ  gu_singu_soutcountsyms_sinclsargdim_symsrW  rX  rV  s                            @@@r3   r   r     s5    '^T5Qab 	QA*aa*;Aw*OP	Q T^+JaefgfhaijZ]#U:J g6PUUjGjI ! !a !! '0I"QINN1yl#MM) 1}MM"#I3xH 
q&h-9Q<q=8 h- 8,J3 FGEHfdi!#%89& !S	CsCCHHJ MM%!4 5Xab\8J JKLMM(# H! Ge ks   !G,c                 Z    t        | j                        D ]  \  }}t        d|d|        y )N    rD   )	enumeraterx   rs   )blockr   r1   s      r3   _print_blockru    s,    UZZ( $4fad#$r4   c                 `    t        |       }|D ]  }| |   }t        d|       t        |         y)z%Pretty-print a set of IR blocks.
    zlabel: N)wrap_find_topors   ru  )	body_dict
topo_orderlabelrt  s       r3   _print_bodyr{    s9      	*J % iUr4   c                    | j                         }t        |j                               }t        |j                               }||   j                  }||   j
                  j                  t        j                  ||             |S r)   )	rq   minkeysr]  rH   rx   r   r   Jump)	loop_bodyblocksfirst_label
last_labelrH   s        r3   wrap_loop_bodyr    sg    ^^Ffkkm$KV[[]#J


 
 C
:""277;#<=Mr4   c                 j    t        | j                               }| |   j                  d d | |   _        y )NrQ  )r]  r~  rx   )r  r  s     r3   unwrap_loop_bodyr    s2    Y^^%&J!*:!6!;!;CR!@Ijr4   c                 ~    | |v ry| |v r#|j                  |        |j                  |        y|j                  |        y)a_  If the variable is already defined more than once, do nothing.
       Else if defined exactly once previously then transition this
       variable to the defined more than once set (remove it from
       def_once set and add to def_more set).
       Else this must be the first time we've seen this variable defined
       so add to def_once set.
    N)r9  remove)a_defdef_oncedef_mores      r3   add_to_def_once_setsr    s;     	(	UUr4   c                 N   | j                  t        j                        }|D ]   }|j                  j                  }t        |||       |j                  }	t        |	t        j                        r=t        |	j                  t        j                        r|	j                  j                  ||<   t        |	t        j                        rL|	j                  dk(  r=|	j                  j                  |v r%|	j                  j                  |	j                  f||<   t        |	t        j                        rs|	j                  dk(  rd|	j                  j                  |v rL||	j                  j                     \  }
}|
|v r||
   }t!        ||      st        |
||       nt        |
||       t        |	t        j                        s|	j                  dk(  s|	j"                  D ]H  }t        |t        j$                        r|j                  }||   }t'        |dd      s<t        |||       J  y)a  Effect changes to the set of variables defined once or more than once
       for a single block.
       block - the block to process
       def_once - set of variable names known to be defined exactly once
       def_more - set of variable names known to be defined more than once
       getattr_taken - dict mapping variable name to tuple of object and attribute taken
       module_assigns - dict mapping variable name to the Global that they came from
    r   r   mutableFN)
find_instsr   r  r  rO   r  r	  r*   Globalpytypes
ModuleTyper8   r   rG  attrr   r   rK   rz   r   )rt  r  r  getattr_takenrp   module_assignsassignments
one_assignr  rM   base_obj	base_attrbase_mod_nameargvaravtypes                  r3   compute_def_once_blockr    s    ""299-K! 0E
!!&&UHh7c299% #))W%7%78(+		(:(:u%c277#)(;		RZ@Z$'IINNCHH#=M% c277#&(8SXX]]m=[ #0">Hi>) !/x 8$]I> )8XF %XxBc277#&(8 (( 
Efbff-#[[F  69e4 )8D
EM0Er4   c                 H    t        |       }t        |      }t        |        |S r)   )r  r   r  )r  r  ry  s      r3   rw  rw  S  s$    I&F (JYr4   c           
         t        |       }|D ]w  }| |   }t        ||||||       |j                  D ]Q  }	t        |	t        j
                        st        |	j                  |||||       t        |	j                  |||||       S y y)zCompute the set of variables defined exactly once in the given set of blocks
       and use the given sets for storing which variables are defined once, more than
       once and which have had a getattr call on them.
    N)	rw  r  rx   r*   r   r+   rw   compute_def_once_internalr  )
r  r  r  r  rp   r  ry  rz  rt  r1   s
             r3   r  r  Y  s      	*J v%  	uh-R`aJJ 	vD$.&t(M[bdrs)$..(Hm]dftu	vvr4   c                 Z    t               }t               }i }i }t        | |||||       ||fS )zRCompute the set of variables defined exactly once in the given set of blocks.
    )r\  r  )r  rp   r  r  r  r  s         r3   compute_def_oncer  m  s:     uHuHMNi8]GUcdXr4   c                 t    t        | t        j                        sJ |j                  | j                         | S r)   )r*   r   rz   r9  rO   )r  varsets     r3   	find_varsr  w  s+    c266"""
JJsxxJr4   c                    | j                   j                  |v r4|j                  | df       t        j                  dk\  rt        d| d       y|| j                   j                     }t               }t        | j                  t        |       |D 	
ch c]  \  }	}
|	j                   j                   }}	}
||z  }|j                  |      }||z  }t        j                  dk\  rt        d| d|d|       t        |      d	k(  rt        | j                  d |      rpt        j                  dk\  rt        d
| |       |j                  |        t        |t        j                  j                         s|| j                   j                  gz  }yt        |      d	kD  r4|j                  | df       t        j                  dk\  rt        d| d       y|j                  | df       t        j                  dk\  rt        d| d       yc c}
}	w )Nzstored arrayrQ   Instructionz9could not be hoisted because the created array is stored.Fz_hoist_internal:zuses:zdiff:r   zWill hoist instructionT
dependencyz-could not be hoisted because of a dependency.znot purez+could not be hoisted because it isn't pure.)r  rO   r   r   rr   rs   r\  r   r	  r  
differencer   r   r*   r   r   r   )r1   dep_on_param
call_tablehoistednot_hoistedrp   stored_arraystarget_typeusesassgn_unhoistableuse_unhoistdiffs                 r3   _hoist_internalr  |  s   {{=(D.12!!Q&-'bc$++**+K5DTZZD15@A5<<$$AKA$K??<(DKD" $wE
4yA~'$**dJ?!!Q&*D+>t+u~~';';<T[[--..Lt9q=l34%%*mT+Z[
  j12%%*mT+XY- Bs    G<c                   	 |j                   D ]  }t        |t        j                  t        j                  f      rp| j                  |j                  j                         t        |j                  j                     dd      sxj                  |j                  j                         t        |t        j                        r1t        | |j                         t        | |j                         t        |t        j                         s|j                  		fd}t        	t        j"                        s4	j$                  dv r	j&                  D ]
  } ||        ]	j$                  dk(  r"	j&                  D ]  }|D ]
  } ||         	j$                  dk(  st)        	j*                        	j,                  D cg c]  }|d   	 c}z   D ]
  } ||         y c c}w )Nr  Fc                     t        | t        j                        sJ        t        | j                     dd      rj                  | j                         y y )Nr  F)r*   r   rz   r   rO   r9  )itemitemssetrM   rp   s    r3   add_to_itemsetz+find_setitems_block.<locals>.add_to_itemset  sG    !$/44/7499-y%@LL+ Ar4   )build_tuple
build_list	build_set	build_mapr   rQ   )rx   r*   r   StaticSetItemSetItemr9  r  rO   r   r	  r   r+   find_setitems_blockrw   find_setitems_bodyr  r  r   rG  r   rb  rK   rS   )
setitemsr  rt  rp   r1   r  r  pairxrM   s
    ` `     @r3   r  r    s}   

  -dR--rzz:;LL))*
 wtzz/EBTZZ__-fmm,(DOOWMx4>>7Kbii( **C,
 #rww'66GG #		 -&t,-VV{* #		 1$( 1D*4011 VVv% $SXX1H1!A$1H H -&t,-? -> 2Is   G3c                 P    |j                         D ]  \  }}t        | |||        y)z
      Find the arrays that are written into (goes into setitems) and the
      mutable objects (mostly arrays) that are written into other arrays
      (goes into itemsset).
    N)r   r  )r  r  r  rp   rz  rt  s         r3   r  r    s.     ") @uHhw?@r4   c           	      t   t        | t        j                        rt        | j                  t        j                        rz| j                  j
                  dk(  ra| j                  j                  j                  |v r?|| j                  j                  j                     }|dt        gk(  rt        | ||||||      S y)Nr   r   F)
r*   r   r  r	  r   rG  r   rO   r   r  )r1   r  r  r  r  rp   r  	call_lists           r3   empty_container_allocator_hoistr    s    4#4::rww'




*tzz334	"%"4z7#.H Hr4   c                 j   t        j                   |       }g }g }t        ||      \  }}t        |      \  }	}
t               }t               }t	        ||||       t        t        |      j                  |            }t        j                  dk\  rt        d|d|d|d|d| 
       |D ]  }t        |||        |j                         D ]f  \  }}g }|j                  D ]G  }t        |||	||||      rt        |t        j                         r*|j"                  j$                  |v rt'        |||	||||      rތZt        |t(        j*                        rg }t        j                  dk\  rt        d       |j-                          |j.                  j                  D ]i  }t        |||	||||      rt        |t        j                         r*|j"                  j$                  |v rt'        |||	||||      rY|j1                  |       k ||j.                  _        |j1                  |       J ||_        i ||fS )NrQ   zhoist - def_once:z	setitems:z	itemsset:zdep_on_param:zparfor_params:r   )rq   r  r   r\  r  rb  r  r   rr   rs   r  r   rx   r  r*   r   r  r  rO   r  r   r+   rv   rw   r   )parfor_paramsr  rp   wrapped_blocksr  r  r  r  r  r  reverse_call_tabler  r  sirz  rt  	new_blockr1   new_init_blockib_insts                       r3   hoistr    s6   99]+LGK *)W=Hh'5n'E$Z#uHuHx9g>L)44X>?L"!8[(KQY[jlx  {K  MZ  	[ 5R845 ")  u	JJ 	#D.t\:#*K(LD")),1A1AX1M"4z#*K(L D&--0!#))Q.(OIIK#33 3G6w"G['8M $Wbii8++x7*7L*+2K+35 %"))'23 (6$T";	#< 
A B Kr4   c                 L    t        | t        j                  j                         S r)   )r*   r   r   r   )redtypes    r3   redtyp_is_scalarr    s    '5>>#7#7888r4   c                     d}t        | t        j                  j                        r|| j                  z  }| j
                  } t        j                  j                  | |d      S )ziGo from a reducation variable type to a reduction array type used to hold
       per-worker results.
    rQ   C)r*   r   r   r   r   rR   )redtypr   s     r3   r   r     sM     I&%..../V[[ 	>>	377r4   c                     t        | t        j                  j                        sJ t        j                  j                  | j                  | j
                  | j                        S )zYGiven a reduction array type, find the type of the reduction argument to the gufunc.
    )r*   r   r   r   rR   r   layout)redarraytyps    r3   redarraytype_to_sigr    sI     k5>>#7#7888>> 1 1;3C3C[EWEWXXr4   c                 h    t        |       }|j                         D ]  \  }}||k7  s||   ||<    |S )aQ   We use ir_utils.legalize_names to replace internal IR variable names
        containing illegal characters (e.g. period) with a legal character
        (underscore) so as to create legal variable names.
        The original variable names are in the typemap so we also
        need to add the legalized name to the typemap as well.
    )r   r   )namesrp   outdictr  ys        r3   legalize_names_with_typemapr  $  sB     U#G $16 GAJ	$
 Nr4   c                 p    t        | t        j                        r| j                  dk(  r| j                  S | S )Nr   )r*   r   ArrayCompatibler   rR   )r  s    r3   to_scalar_from_0dr  4  s+    !U**+66Q;77NHr4   c
           
      0+   t         j                  dk\  rt        d       |j                  j                  }
t        j
                  |j                        }t        |       t        |j                        }|j                  D cg c]  }|j                  j                   }}|j                  }t        j                  j                  j!                  ||      }| j"                  j$                  }t        j                  j                  j'                  | j(                  ||| j"                  j*                        \  }}t-        t/        t1        |      t1        |      z
  t1        |      z
              }t         j                  dk\  r\t        d|dt3        |             t        d|dt3        |             t        d|dt3        |             t        d|dt3        |             g }i }i }d}g }|D ]  }||   }t5        |t6        j8                        st5        |t6        j:                        r|j<                  }|j>                  }|t         j@                  k  sJ g }tC        |      D ]C  }d	tE        |      z   }|jG                  |       |jG                  |       ||f||<   |dz  }|||<   E |||<   |jG                  |       t5        |t6        jH                        st5        |t6        jJ                        r|j<                  }|j6                  } |t         j@                  k  sJ g }tC        |      D ]F  }d	tE        |      z   }|jG                  |       |jG                  |       ||f||<   |dz  }| |   ||<   H |||<   |jG                  |       |jG                  |        |}t         j                  dk\  rt        d
|dt3        |             |	jM                  t1        |            }	|	D ]&  }!d|!z  }"tO        jP                  tS        |"|
             ( tU        |	||| j"                  j*                         g }#g }$|D ]V  }%|%dz   }&|#jG                  |&       tW        ||%         }'|$jG                  |'       tY        |'      }(|&|v r||&   |(k(  rPJ |(||&<   X ||z   |#z   }t         j                  dk\  rPt        d|dt3        |             t        d|dt3        |             t        d|dt3        |             t[        |       t]        ||z   |z   |      })t         j                  dk\  r.t        dt-        |)j_                               dt3        |)             t]        ||      }*|D +cg c]  }+|*|+   	 },}+t         j                  dk\  rut        dt-        |*j_                               dt3        |*             t        d|,dt3        |,             |D ]+  }-t        d|-       t        d||-   dt3        ||-                - |D +cg c]  }+ta        ||+          }.}+||z   D +cg c]  }+||+   	 c}+|$z   }/t         j                  dk\  rt        d|.       t        d|/       tc        ||)       |}0|D +cg c]  }+|)|+   	 }}+|}1g }d}2tC        t        |1            D ]e  }3|2rM|3t        |      k  r?t5        |.|3   t6        jd                  jf                        r|jG                  |1|3   dz          R|jG                  |1|3          g tc        ||*       ti        |      }4tk        d|4      }5t         j                  dk\  rt        d|dt3        |             dtm        to        |            jq                  dd      z  }6t         j                  rt        dt3        |6      d|6       d}7|7d|6z   d z   d!js                  |      z   d"z   z  }7tt        t        d#}8|j_                         D ]8  \  }9}:||9   };|7d$|)|9   z   z  }7t5        |;t6        jJ                        st5        |;t6        j:                        rd%}<nd}<|<rtw        tx        | j(                  |9      }=d&}>t         j                  rt        d'|=t3        |=             |=t5        |=tz        j|                        r[|=j~                  d(k(  rLtw        tx        | j(                  |=j                        }>t         j                  rqt        d)|>t3        |>             nZt5        |=tz        j                        r@||=j                     }>t         j                  r!t        d)|>t3        |>      |>j                         |>t5        |>tz        j                        st5        |>tz        j                        rB|>j                  }?t         j                  rt        d*|?t3        |?             |?|8|>j                  <   nt5        |>t6        j                  j                        r|>j                  j                  d+      d   }@t         j                  r+t        d,@|>j                  t3        |>j                               |>j                  |8@<   n=t         j                  rt        d-       t        d.tE        |9      z   |9j                        |7d/|;j                  j                  z   d+z   z  }7t        |:|;j                        D ]  \  }A}B|7|Bd0z   |)|A   z   d1z   z  }7 n;|7d2d!js                  |:D Ccg c]  }C|)|C   	 c}C      z   z  }7t        |:      dk(  r|7d1z  }7|7d3z  }7; tC        t        |            D ]D  }3|2st5        |.|3   t6        jd                  jf                        s.|7d$|1|3   z   d4z   ||3   z   d3z   z  }7F d5}Dt        |#      dkD  r|7d$Dz   d/z   z  }7|7d6z  }7t        |#|      D ]f  \  }&}%|7d$|)|%   z   d0z   |)|&   z   d7z   Dz   d8z   z  }7t         j                  s4|7d9z  }7|7d:|)|%   z   d1z   |)|%   z   d;z   z  }7|7d<|)|&   z   d1z   |)|&   z   d;z   z  }7h tC        |      D ]K  }EtC        |Edz         D ]  }F|7d$z  }7	 E}G|7d=|,|E   z   d>z   tE        |G      z   d?z   tE        |G|z         z   d@z   z  }7M t         j                  rItC        |dz         D ]  }F|7d$z  }7	 |7dAz  }7tC        |      D ]  }E|7dB|,|E   z   dCz   |,|E   z   d1z   z  }7 |7d3z  }7tC        |dz         D ]  }F|7d$z  }7	 |7|5dDz   z  }7t        |#|      D ]N  \  }&}%t         j                  r|7dE|)|%   z   d3z   z  }7|7dF|)|&   z   d3z   z  }7|7d$|)|&   z   d7z   Dz   dGz   |)|%   z   dHz   z  }7P |7dIz  }7t         j                  r-t        dJt3        |7      dH|7       t        dK|8t3        |8             i }Ht        |7|8|H       |H|6   }It         j                  rt        dLt3        I      dH|I       t        j                  I      }Jt         j                  rEt        dMt3        J             |Jj                          t        dNt3        |             t[        |       ti        Jj                        }Ki }L|5gt/        |)j                               z   |,z   }M|Kj_                         D ]=  \  }A}%|AMvs|j                  j                  j                  A|
      j                  L|A<   ? tc        Jj                  L       t         j                  rt        dO       Jj                          t6        jd                  jg                  |ddP      g|.z   }Nt         j                  rt        dQt3        N      dH|N       t        Jj                        dz   }Ot        ||O      }t        |      dz   }Pt         j                  r|j_                         D ]  \  }Q}R|Rj                         }S|Sj                          |Rj                  }
|Rj                  }T|Rj                  D ]  }USjG                  |U       t5        |Utz        j                        s0|Uj                  j                     t6        j                  vrZdRj                  Uj                  j                        }Vt7        j                  |V      }WTj                  dS|
      }Xt{        j                  t{        j                  |V|
T      |X|
U      }Y|W||Xj                  <   SjG                  |Y       t{        j                  |X|Uj                  gd&|
V      }Z|SjG                  |Z       t        j                  j                  j                  t6        j                  ||Xj                     ||Uj                  j                           }[|[| j"                  j*                  |Z<    S|Q<    t         j                  rt        dW       t[        |       t        |      }\t        ||||\      \  }]}^Jj                  t        |Jj                  j                                  }_|_j                  d&dX |]z   |_j                  dX   gz   |__Y        t        |       | j                  dY   }`|]|^dZ|`j                  |j                  <   t         j                  rt        d[       t[        |       Jj                  j_                         D ]  \  }Q}Rt        |Rj                        D ]l  \  }}Ut5        |Utz        j                        s"Uj                  j                  |5k(  s<Uj                  }
Rj                  }Tt{        j                  |T|
      }a|Rj                  d&| |a_Y        |Rj                  |dz   d& |R_Y        t        |j                               }b|ajG                  t{        j                  |b|
             |j_                         D ]  \  }}ct        |cT      Jj                  |<     t        |j                               }dRJj                  P<   a|Jj                  Q<   |Jj                  |d   jG                  t{        j                  |P|
              n  n t         j                  rt        d\       Jj                          t        Jj                        |J_R        t        |Jj                         t         j                  r3t        d]       Jj                          t        d^|       t        d_|       |j                  }e|s"t         j                  rt        d`       d%|_s        t        Jj                          G da dbt        j                        }ft        j                  |||JNt6        j                  |||fc      }ge|_s        t        t6        j                  g|N }ht         j                  rt        ddh       g|0h|/|fS c c}w c c}+w c c}+w c c}+w c c}+w c c}Cw )ea~  
    Takes a parfor and creates a gufunc function for its body.
    There are two parts to this function.
    1) Code to iterate across the iteration space as defined by the schedule.
    2) The parfor body that does the work for a single point in the iteration space.
    Part 1 is created as Python text for simplicity with a sentinel assignment to mark the point
    in the IR where the parfor body should be added.
    This Python text is 'exec'ed into existence and its IR retrieved with run_frontend.
    The IR is scanned for the sentinel assignment where that basic block is split and the IR
    for the parfor body inserted.
    rQ   z'starting _create_gufunc_for_parfor_bodyzparfor_params = rD   rh   zparfor_inputs = ri   r   expanded_tuple_var_z$parfor_inputs post tuple handling = zVariable %s used in parallel loop may be written to simultaneously by multiple workers and may result in non-deterministic or unintended results._arrzloop_indices = zloop_body = zparam_dict = zind_dict = zlegal_loop_indices = zpd = z
pd type = znew param_types:znew func_arg_types:Fparam__sentinel__zlegal parfor_params = z__numba_parfor_gufunc_%s-r  zgufunc_name  zdef z(sched, z, z):
)r   r|   rr  TNz	func_def:r   znamed_tuple_def:zgval:(zname:z0Didn't find definition of namedtuple for globls.zCould not find definition of z = =,z = (z)
z = np.ascontiguousarray(!ParallelAcceleratorGufuncThreadIdz*numba.np.ufunc.parallel._iget_thread_id()
[z]
z<    print("thread id =", ParallelAcceleratorGufuncThreadId)
zF    print("initial reduction value",ParallelAcceleratorGufuncThreadId,z.shape)
z>    print("reduction array",ParallelAcceleratorGufuncThreadId,zfor z in range(sched[z	], sched[z] + np.uint8(1)):
zprint("z",z = 0
zD    print("final reduction value",ParallelAcceleratorGufuncThreadId,zD    print("final reduction array",ParallelAcceleratorGufuncThreadId,z] = 
z    return None
zgufunc_txt = zglobls:zgufunc_func = zgufunc_ir dump zloop_body dump zgufunc_ir dump after renaming r  zgufunc_param_types = z{} =r^   )r	  rH   )r	  r  rH   r_   zparfor loop bodyrQ  parfor_diagnostics)r  r  zAfter hoistingz#gufunc_ir last dump before renamingzgufunc_ir last dumpr   rp   z(No aliases found so adding noalias flag.c                       e Zd Zd Zy)<_create_gufunc_for_parfor_body.<locals>.ParforGufuncCompilerc                 d   ddl m} t        j                  } |d      }|j	                  | j
                        }|j                  j                  |j                         |j                  | j
                        }|j                  j                  |j                         |j                          |gS )Nr   )PassManagerfull_parfor_gufunc)
numba.core.compiler_machineryr  r   DefaultPassBuilderdefine_parfor_gufunc_pipelinestatepassesextend/define_parfor_gufunc_nopython_lowering_pipelinefinalize)r0   r  dpbpmparfor_gufunc_passeslowering_passess         r3   define_pipelineszM_create_gufunc_for_parfor_body.<locals>.ParforGufuncCompiler.define_pipelines=  s    A--C12B#&#D#DTZZ#P II1889!QQRVR\R\]OII_334KKM4Kr4   N)r8   r9   r:   r  r6   r4   r3   ParforGufuncCompilerr  <  s    
	r4   r  )pipeline_classz5finished create_gufunc_for_parfor_body. kernel_sig = )wr   rr   rs   rw   rH   rq   r  r   r   r   r   rO   r   r|   r}   r   r   ro   rp   get_parfor_reductionsr   r   sortedrb  r\  rt   r*   r   r   NamedUniTuplerl  rR   PARFOR_MAX_TUPLE_SIZEr   r   r   Tuple
NamedTupler  warningswarnr!   replace_var_with_arrayr   r  r{  r  r   r  r   r   r   r   r   hexhashreplacejoinr   r   r   r   r   rG  r   Argr  FreeVarr	  
containersBaseNamedTuplesplitinstance_classr#   r8   r`  fieldsr   execr   run_frontendrv   r  valuesrG   r   r   r   clearrx   r  r  number_domainformatr   Constr   coretypingr   r   r  r  r}  r~  r  metadata
hoist_infoidrs  Blockr  r   r]  r   noaliasr   CompilerBase
compile_ir)ir@   r   rp   r   r   r   localshas_aliasesr   ry   rH   r  
parfor_dimr   loop_indicesr  parfor_outputsr   r   parfor_inputstuple_expanded_parfor_inputstuple_var_to_expanded_namesexpanded_name_to_tuple_varnext_expanded_tuple_varparfor_tuple_paramspipi_typetuple_counttuple_dtypethis_var_expansionr   expanded_nametuple_typesracemsgparfor_redarrsparfor_red_arg_typesr  arrredarraytype	redarrsig
param_dictind_dictr   legal_loop_indicespdparam_typesr   parfor_argsparfor_params_origascontigpindexloop_body_var_tablesentinel_namegufunc_name
gufunc_txtgloblstup_var	exp_namestup_type	named_tupfunc_defnamed_tuple_defgvalnamed_tuple_namerO   
field_namer  gufunc_thread_id_vareachdimindent	sched_dimloclsgufunc_func	gufunc_ir	var_tablenew_var_dictreserved_namesgufunc_param_typesgufunc_stub_last_label	new_labelrz  rt  r  rG   r1   strvalr   r   
assign_lhs
print_noder*  r  r  r  start_blockdiagnostics
prev_blockbody_first_labelbbody_last_label	old_aliasr  kernel_func
kernel_sigsi                                                                                                            r3   r   r   :  sI   , "78




C 		&**+I	V&&'J393D3DEaA$$))ELE MMM]]))<<V]SNnn$$G%*]]%9%9%O%O0H0H&J"NN   	!"M " -d=6IJ!>3^8LM -d=6IJ!>3^8LM $& "$!# .4"+gu~~.*WeFYFY2Z!--K!--K&">">>?>!#;' 5 5<S8T T,33MB"))-8 >@G*=9'1,')4&5 /A'+&&r*-GUEUEU1V "--K!--K&">">>?>!#;' 8 5<S8T T,33MB"))-8=?G*=9'1,')4Q&8 /A'+&&r*(//3].4^ 1M"4mS$}J]^ S01E <=?CD 	0c:;	<
 5)Wgnn6N6NO N 	%Flc"-gcl;##L1'5	'>3<9,-,$GCL	% "N2^CM" -d=6IJsD4FGnid9o>I -]^-KNa-acjkJ"  "$	 +<AH/;<!(1+<<"mVHNN$45sDNK##$		&
   	EB'2,S$wr{2CD	E
 ;HHQ$WQZ0HKH+8>+IKQgajKNbbN" +.#^4 i,K,9:qZ]:M:&MH./0 =S''{6*ENN,@,@A  !3F!;G!CD  !3F!;<= i*,Y7'8KLM"$		! -DL!!#s+-Knd;/kBJ &;&ii.0289 9J 'F
 :??A :7#fz'222
x!1!12x!4!45II ^W__gFH"O%%k8T(^<#x1KK6)&+NGOOX]]&[O--0/4CXY"&&1&-hmm&<O--0/"?3_5I5IK*		:

;*00D--gtT$Z837F?//01A1A1P1PQ'6';';'A'A#'Fq'I$--g'7-<<"?#A#ABD 0?/M/MF+,))LM#$Cc'l$R%,[[2 2%("9"9"B"BBSHHJ$'	8??$C H jj3.D1AACGG
H &499Y-Ojm-O#PPPJ9~" c!
e
u:x M*+ N
;v#68L8LM6$6v$>>,-/<V/DEGLM NJN
 ?
>Qf33e;;
CC
 7 USfz#.c?#%()+?@BGH 	H
))[[Jdgqrugvvy||  @J  KN  @O  O  R]  ]  ]J\_ijm_nnqtt  xB  CF  xG  G  JU  U  UJU $ .GaK( 	!F& J	!	v)'23)* 9~& #	#
 9%& '' -- 	.
	. %%JN+ 	!F& J	!h
Z( 	iG$!3G!<<uDGYZaGbbehhhJ	ie
 
Q' f
-(**J7 IS))beopsettw|||Jbeopsettw|||Jfz#.&')/02<S/BDHI 	I
I %%JotJ/zBif.EVU#$K[ 14E%%k2Ii1i1I #9#3#34IL#_Z !"$67N__& R	c&!'!2!2!8!8!A!A$!L!Q!QLR i&&5./....1c# $&12##$		  ,I,<,<=A %Y0FGIy)A-I %%%OO- 	)LE5

IOO))CKKE

 ?  &dBII.t{{//08K8KK  $]]4;;+;+;<F"'"5"5f"=K..c:C!#C1P253"@J(3GCHH%$$Z0 "$T[[/A$TW!XJ$$Z0**++55ejj+2388+<+24;;3C3C+DFC <?GNN,,Z83?4  )Ie?	)B  !I#I.N 	7NSG[""3y'7'7'<'<'>#?@K"'',w6+:J:J2:N9OOKY ""#78K4;8C)EK699% I "((..0 #u , !	GAtII#';;#3#3}#Dhh  XXeS1
"'**Ra.
"ZZA/
#&y~~'7#8  !!"''*:C"@A (oo/ CFQ*8E*BI$$Q'C"%inn&6"7.3	  +*4	  '   188GGIs+-?!	B G#J 34$Y%5%56I	  !#$gui!I!!<=i../x44  %%

+-K EM5::;(:;JEzRZA[[[y FD = IK ;@ .Ps*   AU:!AU?;AVAV	(AVAVc           	         g }|j                   D ]:  }t        |t        j                        r|j                  j
                  | v r|j                  }|j                  j                  }t        j                  d|      }|j                  d|      }	t        j                  ||	j
                  <   t        j                  ||	|      }
|j                  |
       |j                  d|      }||j                  j
                     ||j
                  <   |j                  t        j                  |j                  ||             t        j                  |j                  |	||      }t        t        j                   t        j"                  j%                  ||j                  j
                     dd      t        j&                  ||j                  j
                           ||<   |j                  |       t        |t(        j*                        r2t-        | d|j.                  i||       t-        | |j0                  ||       |j                  |       = |S )Nr   z$const_ind_0z$valrQ   r  )rx   r*   r   r  r  rO   rH   rG   r#  r   r   rB  r   r	  r  r   r   r   r   rb   r   r+   replace_var_with_array_internalrw   r  )varsrt  rp   r   r  r1   rH   rG   
const_node	const_varconst_assignval_varsetitem_nodes                r3   replace_var_with_array_in_blockr~  [  s   I

 dBII&4;;+;+;t+C((CKK%%E!S)J~s;I&+kkGINN#99ZC@L\*nnVS1G$+DKK,<,<$=GGLL!RYYtzz7C@A::dkk9gsKL&/

ENN009I9I1JAsSUZU_U_ahimititiyiyaz'|Il#\*fmm,+D1doo2FQZ[+D$..'9U/0 r4   c                 Z    |j                         D ]  \  }}t        | |||      |_         y r)   )r   r~  rx   )rx  r  rp   r   rz  rt  s         r3   rw  rw  w  s0    !) Vu4T5'9U
Vr4   c                     t        | |||       | D ]=  }||   }|j                  |d        t        j                  j	                  |dd      ||<   ? y )NrQ   r  )rw  popr   r   r   )rx  r  rp   r   r   el_typs         r3   r  r  {  sR    #D)WiH :At^^))&!S9
:r4   c                 (   gh  j                   h j                  gddlm}m} t
        j                  rrt        d       t        d|j                  |j                  |j                  |j                         t        d|       t        d|       t        d|       t        d|       t        j                  |      \  }}|j                  j                  |j                   j"                        }|\  }} |         |||||d	d
      }|j$                  }|j                  j'                          t
        j                  rt        d||       h fd}t)        |      }t+        |      D ]  }||   \  }}} ||      } ||      }|dk(  sJ  ||      }|||f||<   t
        j                  sDt        dj-                  |      |||       t/        j0                  gdj-                  |      |||        t2        j4                  j7                  d      }t2        j4                  j9                  |      }t2        j4                  j9                  |      }hj;                  t<        j>                        } hj;                  t<        j@                        }!t2        j4                  j9                  |       }"t2        j4                  j9                  |"      }#t2        j4                  j9                  |!      }$t2        j4                  j9                  |$      }%hjC                  t<        j@                  d      }&hjC                  t<        j@                  d      }'|'jD                  }(hjG                  |       })|jI                  d       |jI                  d      }*t
        j                  rt        d|jJ                         |jJ                  r| }+|"},|#}-n|!}+|$},|%}-t/        jL                  g|+hjC                  t<        j@                  |      d      }.t/        jL                  g|+hjC                  t<        j@                  |      d      }/t+        |      D ]  }||   \  }}}|jD                  |(k7  rgjO                  ||(      }|jD                  |(k7  rgjO                  ||(      }|jD                  |(k7  rgjO                  ||(      }gjQ                  ||'      }gjS                  |gjU                  |.hjC                  t<        j@                  |      g             gjS                  |gjU                  |/hjC                  t<        j@                  |      g              t/        jV                  gjX                  t2        j4                  j[                  |!g       d      }0t/        jV                  gjX                  t2        j4                  j[                  t2        j4                  j]                         |!g      d      }1t/        jV                  gjX                  t2        j4                  j[                  t2        j4                  j7                  t<        j>                  j^                        g       d      }2gja                  |2g       }3gja                  |0g       }4t/        jb                  ggje                  d|3|3jE                  d                  5  t/        j0                  gd|3       hjf                  ji                  gtj        d       ddd       t2        j4                  j[                  |!|!|!|"|"g      }5t/        jV                  gjX                  |5d      }6gja                  |6|3hjC                  t<        j@                  |      |.|/g      }7gja                  |1|&g       hjC                  t<        j@                  |dz        }8gjm                  |7|8      }9t2        j4                  j[                  |,|!g      }:t/        jV                  gjX                  |:d       };gja                  |;|9g      }<t/        jL                  g|,      }=gjS                  |<|=       t
        j                  rdnd}>t2        j4                  j[                  |"|!|"|"|!|,| g      }?|jJ                  r#t/        jV                  gjX                  |?d!      }@n"t/        jV                  gjX                  |?d"      }@gja                  @hjC                  t<        j@                  |      |.|/|7gjo                  |=      hjC                  t<        j>                  |>      g       |D Acg c]   }A jq                  |	|A   j$                        " }B}At)        |      }Ct)        |      |Cz
  }Dg fd#}E|d|D D Acg c]
  }A E|A       c}ABz   }Ft)        |F      }Gt)        |      dz   }Ht/        jL                  g|hjC                  t<        j>                  d|Gz         d$      }g }IgjS                  gjs                  gjo                  |=      |      |       |Iju                  hjC                  t<        j>                  |)             i }Jt+        |G      D ]  }F|   }K||   }L||   }MgjU                  |hjC                  t<        j>                  |dz         g      }N|Dk\  r hjw                  M      hgK      }Ot/        jx                  g|Ojz                  |Mj|                        }Pt+        t)        |P            D ]  }QIju                  P|Q           gjS                  gjs                  Oj~                  |      N       t        Mt<        j                        rL|v rMj                  t<        j                  k7  rhj                  Mj                        nt2        j4                  j7                  d      }Rt/        jL                  g|R      }SgjS                  K|S       gjS                  gjs                  |S|      N       |K|SfJL<   Iju                  hjC                  t<        j>                  hjG                  |R                    hjw                  M      hgK      }Ot/        jx                  g|Ojz                  |Mj|                        }Pt+        t)        |P            D ]  }QIju                  P|Q           gjS                  gjs                  Oj~                  |      N       |Hk  rt        Mt<        j                        r!MjD                  }Thj                  gK|M|T      }KnM}Tt        Tt<        j                        shj                  T      nt2        j4                  j7                  d      }Rt/        jL                  g|R      }UgjS                  K|U       n`t        Mt<        j                        shj                  M      nt2        j4                  j7                  d      }Rt/        jL                  g|R      }UgjS                  gjs                  U|      N        i }Vg }W|*d   g}WhjC                  t<        j>                  d|z        |V|*d   <   t)        |      t)        F      k(  sJ t)        |      t)        |      k(  sJ t)        |      t)        ||z         k(  sJ t)        |      t)        |j                  dd       k(  sJ t        |F|||z         D ]W  \  }L}K}M}Xt        |Mt<        j                  j                        rMj|                  t)        X      z
  }nd}t
        j                  rt        d%Ld&Xd'Md(|       XD ]  }Yt
        j                  rt        d)Ld*M       L|v r$hjC                  t<        j>                  d      VY<   nL hjw                  M      hgK      }Ot/        jx                  g|Oj                  |Mj|                        }Z|Z|   VY<   YWvrLt
        j                  r+t        d+Yd,|       t/        j0                  g|Yd-z   V|Y          Wju                  Y       |dz   } Z t)        V      dz   }[t/        jL                  g| |[d.      }ZgjS                  |7|Z       d}WD ]x  }Yt
        j                  rt/        j0                  gYd-z   V|Y          gjS                  VY   gjU                  ZhjC                  t<        j>                  |      g             |dz   }z Gdz   t)        I      z   }\t/        jL                  g| hjC                  t<        j>                  |\      d/      }]gjS                  hjC                  t<        j>                  d|z  |)z        |]       t+        |G      D ]J  }|&}^gjU                  ]hjC                  t<        j>                  d|z         g      }NgjS                  |^|N       L t+        t)        I            D ]N  }QgjU                  ]hjC                  t<        j>                  dGz   |Qz         g      }NgjS                  I|Q   |N       P t/        j                  |      }_t2        j4                  j[                  t2        j4                  j]                         ||"|"|g      }`t/        jV                  gjX                  |`|      }ahj                  j                  |j                         t
        j                  rt/        j0                  gd0a       gja                  a|Z]_g       t
        j                  rt/        j0                  gd1a       gja                  |1|4g       t2        j4                  j[                  t2        j4                  j]                         |,g      }bt/        jV                  gjX                  |bd2      }cgja                  |cgjo                  |=      g       Jj                         D ]k  \  }d}e|e\  }K}SgjU                  |ShjC                  t<        j>                  d      g      }fgjS                  gjo                  |f       j                  |d             m hj                  j                  |j                         y# 1 sw Y   hxY wc c}Aw c c}Aw )3zF
    Adds the call to the gufunc function from the main function.
    r   )build_gufunc_wrapper_launch_threadsmake_parallel_loopzouter_sig = rj   	expr_argsexpr_arg_typesr   FT)cache
is_parforszparallel function = c                     t        | t        j                        rj                  | j                        S j                  t        j                  |       S r)   )r*   r   rz   r   rO   get_constantr   rB  )r   rl   r@   s    r3   
load_rangez(call_parallel_gufunc.<locals>.load_range  s;    a ??166**''Q77r4   rQ   z'call_parallel_gufunc loop_ranges[{}] = zloop range[{}]: %d %d (%d)
   z%Parfor has potentially negative start
dim_starts)sizerO   	dim_stopsget_parallel_chunksizerX   set_parallel_chunksizer   z<=znum_threads: %d
)z@Invalid number of threads. This likely indicates a bug in Numba.Nget_sched_size   allocate_scheddo_scheduling_signeddo_scheduling_unsignedc                     | v r-|    \  }}j                  |      }j                  ||      }|S j                  |       S )a?  Given a variable name, if that variable is not a new name
           introduced as the extracted part of a tuple then just return
           the variable loaded from its name.  However, if the variable
           does represent part of a tuple, as recognized by the name of
           the variable being present in the exp_name_to_tuple_var dict,
           then we load the original tuple var instead that we get from
           the dict and then extract the corresponding element of the
           tuple, also stored and returned to use in the dict (i.e., offset).
        )r   extract_value)r  orig_tupoffsetrT  resrn   r   r@   s        r3   load_potential_tuple_varz6call_parallel_gufunc.<locals>.load_potential_tuple_varM  sQ     %%4Q7Hfooh/G''8CJ??1%%r4   pargszvar =zgu_sig =ztype =zi =zvar = z type = z
dim_sym = z, i = z = %d
pshapepstepszbefore calling kernel %p
zafter calling kernel %p
deallocate_sched)Qrl   rn   rk   r  r  r   rr   rs   rK   return_typerecvrpysigr	   normalize_signaturelibraryget_functionro   llvm_func_namerO   _ensure_finalizedr   r   r"  r
   printfllvmliter   IntTypePointerTyper   r   rb   rB  r  rt   get_abi_sizeofr  signedr   sextr:  r   gepget_or_insert_functionmoduleFunctionTypeVoidTypebitwidthr   if_unlikelyicmp_signed	call_convreturn_user_excRuntimeErrorr>  loadr   bitcastr   
make_arrayunpack_tuplestridesr   datar*   r  rR   booleanget_data_typeOptionalcastBooleanr`  r   r   rT   get_null_valueactive_code_libraryadd_linking_libraryr   getvar)ir@   cresr   	outer_sigr  r  r   r   r   
redarrdictrw   r   ry   r   r  r  rK   r  	llvm_funcsinsoutinfowrapper_namer  num_dimr   r   r   r   byte_t
byte_ptr_tbyte_ptr_ptr_tintp_tuintp_t
intp_ptr_tintp_ptr_ptr_tuintp_ptr_tuintp_ptr_ptr_tzerooneone_typesizeof_intp	sched_sig
sched_typesched_ptr_typesched_ptr_ptr_typer  r  get_chunksizeset_chunksizer   num_threadscurrent_chunksizeget_sched_size_fntyr  num_divisions
multiplier
sched_sizealloc_sched_fntyalloc_sched_funcalloc_spacerg   
debug_flagscheduling_fntydo_schedulingr  r   r   ninoutsr  all_argsnum_argsnum_inpsarray_stridesrv_to_arg_dictro  r  atydstaryr  r   rN   rv_argunpacked_atyptrsig_dim_dictoccurrencesgu_sigdim_symshapesnshapes	num_stepsstepsstepsizer  fntyr
  dealloc_sched_fntydealloc_sched_funckr   only_elem_ptrrn   rl   si   `            `                                                                                         @@r3   r   r     sm    ooGooG, "#ninni.C.Cooy	0,k9%/nl+ !44Y?D+))$++*D*DEIIC 	4d&+>D99LLL""$$lD98 +G7^ .'NtT5!$qyy$t,A!!;BB1EuNN7$B$I$I!$L $.. [[  #F((0J[[,,Z8N##EJJ/F$$U[[1G((0J[[,,Z8N++))'2Kkk--k:OQ/D


u{{A
.CxxH((0K MM!
I5}7K7KL
#+
$, $$'"6"6KK#"(46J ##'"6"6KK#"(35I 7^ Q'NtT::!LL1E99 <<h/D99 <<h/D{{4%7;;((Q()*	+
 	dGKK	)0)=)=ekk1)M(NP 	QQ& 22  "-%'M
 22  !5!5!7'C%'M
 44  !4!4UZZ5H5H!I2NO ,,3K]B7			Wg&9&9$2=2B2B12E'G 
H ^w 3[A))'<3]	^^ #++227Wgz[e<fg33N LL+292F2Fu{{T[2\2<2;2= >M
 LL' %%ekk7Q;?J]J7J  {{//	J55 ,,/*>K8EMM+u%,,!Jkk..Wj*g~vVXO66w~~7F<RT  66w~~7F<TV
 LL  W&'19mLL!5!5JJ
",-. =DDqwz!}112DGD7|H)nx'G&( 6?x5HI(+IGSH8}H3x!|H!!JJL D MMM'//',,u"5zBDI--ejj+FGN8_ 2AqklQkk$!5!5ejj!a%!H IJ<)'$$S)'7C@C**7CKKJG3w<( 1$$WQZ01MM'//#((J?EU223e|))u}}4 ,,SYY7$KK//2  !,,Wc:c6*goofjA3G'*Fms#$$W%9%9%**gF\F\]`Fa%bc-g((-gwD!..wSXXNs7|, 5A!((45goochh
CSI8|c5>>2#&88L!,,wS,GC#&L(u}}E ,,\:$KK//2  ))'37c3' )emm< ,,S1$KK//2  ))'37MM'//#z:C@e2Al LKQ<.K!(!5!5ejj!g+!NL1y>S]***y>S0000y>St_,,,y>S!34444!$Y%3S4Z"A S#vc5>>//03v;&AA!!'3
FHc5!L 	G%%hZ5e|(/(<(<UZZ(KW%-g((-gwD --gsyy#((K(.q	W%{*)),1=NN7Gi,?gAVW""7+AA	: ,!#G  &wXNFMM-(	A !!NN7Gi$7g9NO!7;;((

A'($)	*
 E 1s=11Ig22JJ	#)13E MM'&&uzz1w;3LM 8_ %kk%'"6"6uzz1q5"I!JKh$% 3}%& -kk$$JJHq 0234 	mA&,- !!*-D;;##HKK$8$8$:%3Z%/%=>D 
	'	'l	KB33DLLAw <bALLdFE401w ;R@LL!2 34 "11(++2F2F2H>JZ[ 77! LL#gll5&9%:;$$& F1VFW-A-A%**a-P,QRgll=17>>!3DEF
 33DLLAU^ ^| E2 Js   29AQ%%AQ3AQ#QAQ)\rq   r6  r   r  r  dataclassesr   llvmlite.irr  rf   r   r|   numba.parforsr   
numba.corer   r   r   r	   r
   numba.core.ir_utilsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   numba.core.typingr   r   numba.parfors.parforr    numba.core.errorsr!   r"   r#   r$   #numba.parfors.parfor_lowering_utilsr%   Lowerr'   r,   rA   r   r   r   r   r   r  r  r  r  r  r   ru  r{  r  r  r  r  rw  r  r  r  r  r  r  r  r  r  r   r  r  r  r   r~  rw  r  r   r6   r4   r3   <module>r     sf        &      E E     * (  8  F(.. */R-j
   !@HE} E
"
J$
L	 6r!FCJ$A <E|v(
$L!-F@
3 j9
8Y _\B8V:RBr4   