
    xKgS                    @   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& d dl'm(Z( d dlm)Z) d dl*m+Z+ d d	l,m-Z-m.Z.m/Z/m0Z0 d d
l1m2Z2  G d de)jf                        Z4d Z5d Z6 edg dd      Z7d Z8 G d de0      Z9d 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/ ZSd0 ZTd1 ZUd2 ZVd3 ZWd4 ZXd5 ZYy)6    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)	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     a/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/parfors/parfor_lowering.pyr-   zParforLower.lower_inst1   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 )r/   s    r2   _disable_sroa_like_optz"ParforLower._disable_sroa_like_opt7   s     r3   )__name__
__module____qualname____doc__r-   propertyr6   __classcell__r1   s   @r2   r&   r&   ,   s!    +%  r3   r&   c                 X    |j                   t        | |      S  |j                   | |      S r(   )lowerer_lower_parfor_parallel_std)r?   r   s     r2   r+   r+   A   s,    ~~)'6::v~~gv..r3   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  rw|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                        tY        jp                  tX        jZ                  |       fdtY        jb                  |      i      }!|g}"te        |tX        jf                  jh                        r|jU                  t*        jr                  ju                  |d|	      tY        jp                  tX        jZ                  |jj                        d      }#t]        |jj                        D ]U  }$|jU                  t*        jr                  jw                  |#|$d
|	      tX        jZ                  d      }%|"jy                  |%       W |j{                  |"d      }&|j|                  j                  |      }'|j                  |'tY        jb                  |            }(|jW                  |!|&|(g      })|jU                  |)|d      }*|*||j0                  <   |jy                  |*       ||   j                  }+|+te        |tX        jf                  jh                        r|jI                  tJ        j                  to        tJ        j                        tY        jp                  tX        jZ                  |jj                        |fdtY        jb                  |      i      },|j                  |+|d      }-|jW                  |,#|-|(g      }.|jU                  |.|d       }/|jy                  |/       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   Bx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locr5   )fobjftypeargs)rJ   num_threads_var)rhstypnamereduction_info   dtype)rH   rI   rJ   kwsshaperedarr_shaperedshapeonedimtuple_size_varrN   )cvalrM   redarrinit_val)rX   rM   rN   redtosetzres_print1 for redvar :	str_constrJ   varargrG   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 = )rG   z_lower_parfor_parallel done)bnumba.np.ufunc.parallelrB   r   contexttyping_contextbuilderfndesctypemapcopyr   DEBUG_ARRAY_OPTprinttypevarmapdump
init_blockrG   rF   bodyr-   racesr   Var_alloca_varrN   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   ra   rangeredtyp_to_redarraytyperQ   DTyper)   npytypesArrayndimemptyr   UniTupleExprgetattrstatic_getitemappendmake_tuple_variable
_typingctxresolve_value_typemake_const_variablerZ   fullDEBUG_ARRAY_OPT_RUNTIMEstrStringLiteralPrintr   none	calltypesget_value_typer
   alloca_onceredefine	for_rangeloadvarstorerc   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   rB   	typingctx	targetctxrm   orig_typemapro   rt   rG   rF   instrracevarrvtyprvrD   rE   parfor_output_arraysparfor_redvarsparfor_reddictnredvarsredarrs
to_cleanuppfbdrget_num_threadsrK   ired_name
redvar_typredvarredarrvar_typreddtype	redarrdimglbl_np_emptysize_var_listredshape_varj	onedimvarsize_varrX   dt
empty_call
redarr_varrZ   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                                                                         r2   r@   r@   H   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! (
 <<& G$Ew,B/	   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A%a(H //9JVVE8S1F 3:>M$**H%%$!KK)#)	 *enn&:&:;&OOa/		
 "66XX&rxx0NN5::y9 ekk(34 7 M --M *enn&:&:;$||=uzz:??C'  ,   z/A %GG22<D#N!JJ- !- !I
 "((3 0 00$4 1 H
 ##66x@D**%++h:O*PBM2GJM & J
 $.GFKK j)%h/88H#j%..*>*>? &+%?%?WW.rww7!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dhldjj.9 *4KQYZ edG !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H6GAGGQVVQVV,6GKHov001,  !|+GWno	

 266!&&c23  *GNN+, c ed2 ;@70 Is   >1p(-p5 %*q(p2	5!q_ReductionInforedvar_inforedvar_namer   r   
redarr_typrZ   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)
itemsrn   ro   rN   r   r   r   redop_lower_trivial_inplace_binops_lower_non_trivial_reduce)r   r   r?   r   thread_count_varr   r   r   r   rZ   reduce_infohandlers               r2   r   r     s     $+==?Z ^^++K8
^^++JOO<
??;/$(5#!!!
 "--33? 11 	 	!1;?- $3r3   c                        e Zd Z fdZ xZS ) ParforsUnexpectedReduceNodeErrorc                 *    t         |   d|        y )Nz!Unknown reduce instruction node: )r,   __init__r.   s     r2   r   z)ParforsUnexpectedReduceNodeError.__init__  s    <TFCDr3   )r7   r8   r9   r   r<   r=   s   @r2   r   r     s    E Er3   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_binoprW   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targetrN   r   _fix_redvar_name_ssa_mismatchr   r   print_variablerG   r7   )r   r?   r   r   r0   r	  redvar_resultvarnames           r2   r   r     s>    ''44#GT2)$0G0GYB3G-{M ]1A1AB)$0G0GQB3G-{M ]1A1AB 3488 )$#.#:#:<3 54 %%))zzl)BKK=G9BG	
 &r3   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(   rW   ).0var	init_names     r2   	<genexpr>z,_lower_non_trivial_reduce.<locals>.<genexpr>
  s     N=McCHH	1=Ms   Nz: parfor non-trivial reduction r  )r   rn   ro   
setdefaultr   r   rN   r
   r   rm   rc   r   r  r  r)   r   Assignany	list_vars_emit_getitem_callr  r-   r   r  r   r   r  rG   )r   r?   r   r   num_thread_llvalr   tidr0   elemr  r  s             @r2   r   r     s[    **+51INN%%i1G1GH '7'<'<=			7??,<	=jj++88D'6T299-NT^^=MNN)#wD  y1""4( 7t<< -VWd'2'>'>@% 9 
>, %%))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.
    rW   TF)	r)   r   r  r  ry   r   rN   r  r  )r?   r0   loadeds      r2   r  r    s\    
 $		"z$**bff'E1dkk&6&67r3   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(   r5   )rY   rc   s     r2   reducer_getitemz+_emit_getitem_call.<locals>.reducer_getitem-  s    e}r3   )rm   rk   r   r   r   rN   r   r   r   ra   compile_internal)idxr?   r   r$  rm   ctxr   arg_arrrJ   sigr  s              r2   r  r  *  s|     ooG
//C''Jook4499:GS>D
K**J


CC#tDDKr3   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_countrY   initcr   s        r2   reduction_addz._emit_binop_reduce_call.<locals>.reduction_add>  (    |$ANA %r3   c                 :    |}t        |       D ]
  }|||   z  } |S r(   r,  r-  s        r2   reduction_mulz._emit_binop_reduce_call.<locals>.reduction_mulD  r2  r3   Nr^   )$operatoriaddisubaddsubimul	ifloordivitruedivmulfloordivtruedivrk   rm   r   r   r   rN   r   r   rF   getr   r   r   rG   rn   ro   r   r   r   r   r-   rZ   r   uintpr%  )r  r?   r   r   r1  r4  kernelr'  rm   r   r(  init_varr   ro   arg_thread_countrJ   r)  r  s                     r2   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r3   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   oprL   rN   )r0   r   rF  rL   s       r2   r  r  s  sZ     dBII&
**Cc277#
vv|
ww||+e,,r3   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.
    rW   TF)rv   rF   r)   r   r  	get_exactunversioned_namer  r!   rN   r   r  )
r   r?   r0   r   rF   reduction_varredvar_unver_nametarget_unver_nameis_same_source_varrd   s
             r2   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   rP   Nargument)ro   )r   alatest_alphac                 N    | dk\  r||    S dxx   dz  cc<   t        d         S )Nr   rR  rP   )chr)r0  	class_map
alpha_dicts     r2   
bump_alphaz+_create_shape_signature.<locals>.bump_alpha  s4    6Q<~&!+&z.122r3   r5   rJ   classesthreadcount_ordinalc              3   0   K   | ]  } |        y wr(   r5   )r  r0  rW  rU  s     r2   r  z*_create_shape_signature.<locals>.<genexpr>  s     Cs!Z95ss   )r   rq   rr   rs   r   setr8  maxinsertordrT  ziptupler   list)r   r   r   rJ   r   rx   ro   r   
num_inoutsr  rX  	class_set_class	max_classthread_num_classalphabetnrY  gu_singu_soutcountsyms_sinclsargdim_symsrV  rW  rU  s                            @@@r2   r   r     s    '^T5QabA*aa*;Aw*OP  T^+JaefgfhaijaiZ]#U:J g6PUUaiG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    rC   )	enumeraterw   rr   )blockr   r0   s      r2   _print_blockrt    s'    UZZ(4fad# )r3   c                 b    | j                         D ]  \  }}t        d|       t        |        y)z%Pretty-print a set of IR blocks.
    zlabel: N)r   rr   rt  )	body_dictlabelrs  s      r2   _print_bodyrx    s+     ")uiU *r3   c                    | j                         }t        |j                               }t        |j                               }||   j                  }||   j
                  j                  t        j                  ||             |S r(   )	rp   minkeysr\  rG   rw   r   r   Jump)	loop_bodyblocksfirst_label
last_labelrG   s        r2   wrap_loop_bodyr    sg    ^^Ffkkm$KV[[]#J


 
 C
:""277;#<=Mr3   c                 j    t        | j                               }| |   j                  d d | |   _        y )NrP  )r\  r{  rw   )r}  r  s     r2   unwrap_loop_bodyr    s2    Y^^%&J!*:!6!;!;CR!@Ijr3   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)r8  remove)a_defdef_oncedef_mores      r2   add_to_def_once_setsr    s;     	(	UUr3   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  rN   r  r  r)   Globalpytypes
ModuleTyper7   r   rF  attrr   r   rJ   ry   r   )rs  r  r  getattr_takenro   module_assignsassignments
one_assignr  rL   base_obj	base_attrbase_mod_nameargvaravtypes                  r2   compute_def_once_blockr    s    ""299-K!
!!&&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 ((fbff-#[[F  69e4 )8D #M "r3   c           
         | j                         D ]u  \  }}t        ||||||       |j                  D ]Q  }t        |t        j
                        st        |j                  |||||       t        |j                  |||||       S w 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)	r   r  rw   r)   r   r*   rv   compute_def_once_internalr}  )	r}  r  r  r  ro   r  rw  rs  r0   s	            r2   r  r  P  sz     ")u 	uh-R`aJJD$.&t(M[bdrs)$..(Hm]dftu  *r3   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}  ro   r  r  r  r  s         r2   compute_def_oncer  b  s:     uHuHMNi8]GUcdXr3   c                 t    t        | t        j                        sJ |j                  | j                         | S r(   )r)   r   ry   r8  rN   )r  varsets     r2   	find_varsr  l  s+    c266"""
JJsxxJr3   c                 .   | j                   j                  |v r4|j                  | df       t        j                  dk\  rt        d| d       y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 |      rt        j                  dk\  r$t        d
| || j                   j                            |j                  |        t        || j                   j                     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 arrayrP   Instructionz: could 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  rN   r   r   rq   rr   r[  r   r  r  
differencer   r   r)   r   r   r   )r0   dep_on_param
call_tablehoistednot_hoistedro   stored_arraysusesassgn_unhoistableuse_unhoistdiffs                r2   _hoist_internalr  q  s   {{=(D.12!!Q&-'cd5DTZZD15@A[5<<$$[KA$K??<(DKD" $wE
4yA~'$**dJ?!!Q&*D'$++:J:J2KLt'$++"2"23U^^5I5IJT[[--..Lt9q=l34%%*mT+[\
  j12%%*mT+YZ- Bs   7 Hc                 2   |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                  }t        |t        j"                        s-|j$                  dv rI|j&                  D ]8  }t        ||j                     dd      s|j                  |j                         : |j$                  dk(  st)        |j*                        |j,                  D cg c]  }|d   	 c}z   D ]8  }t        ||j                     dd      s|j                  |j                         :  y c c}w )Nr  F)build_tuple
build_list	build_set	build_mapr   rP   )rw   r)   r   StaticSetItemSetItemr8  r  rN   r   r  r   r*   find_setitems_blockrv   find_setitems_bodyr}  r  r   rF  r   ra  rJ   rR   )setitemsitemssetrs  ro   r0   rL   itemxs           r2   r  r    so   

dR--rzz:;LL))*
 wtzz/EBTZZ__-fmm,(DOOWMx4>>7Kbii( **C#rww'66TT #		"7499#5y%H$LL3 !* VVv% $SXX1H1!A$1H H"7499#5y%H$LL3 !I/ . 2Is   H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}  ro   rw  rs  s         r2   r  r    s'     ")uHhw? *r3   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   rF  r   rN   r   r  )r0   r  r  r  r  ro   r  	call_lists           r2   empty_container_allocator_hoistr    s    4#4::rww'




*tzz334	"%"4z7#.H Hr3   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 )NrP   zhoist - def_once:z	setitems:z	itemsset:zdep_on_param:zparfor_params:r   )rp   r  r   r[  r  ra  r  r   rq   rr   r  r   rw   r  r)   r   r  r  rN   r  r   r*   ru   rv   r   )parfor_paramsr}  ro   wrapped_blocksr  r  r  r  r  r  reverse_call_tabler  r  sirw  rs  	new_blockr0   new_init_blockib_insts                       r2   hoistr    s!   99]+LGK *)W=Hh'5n'E$Z#uHuHx9g>L)44X>?L"!8[(KQY[jlx  {K  MZ  	[R84  ")u	JJD.t\:#*K(LD")),1A1AX1M"4z#*K(L D&--0!#))Q.(OIIK#33G6w"G['8M $Wbii8++x7*7L*+2K(T %"))'2  4 (6$T"9 : 
? *@ Kr3   c                 L    t        | t        j                  j                         S r(   )r)   r   r   r   )redtypes    r2   redtyp_is_scalarr    s    '5>>#7#7888r3   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.
    rP   C)r)   r   r   r   r   rQ   )redtypr   s     r2   r   r     sM     I&%..../V[[ 	>>	377r3   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   rQ   r   layout)redarraytyps    r2   redarraytype_to_sigr    sI     k5>>#7#7888>> 1 1;3C3C[EWEWXXr3   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   )namesro   outdictr  ys        r2   legalize_names_with_typemapr    s=     U#G16 GAJ	  
 Nr3   c                 p    t        | t        j                        r| j                  dk(  r| j                  S | S )Nr   )r)   r   ArrayCompatibler   rQ   )r  s    r2   to_scalar_from_0dr    s+    !U**+66Q;77NHr3   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.
    rP   z'starting _create_gufunc_for_parfor_bodyzparfor_params = rC   rg   zparfor_inputs = rh   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{   rq  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  rG   )r  r  rG   r^   zparfor loop bodyrP  parfor_diagnostics)r  r  zAfter hoistingz#gufunc_ir last dump before renamingzgufunc_ir last dumpr   ro   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)r/   r  dpbpmparfor_gufunc_passeslowering_passess         r2   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4Kr3   N)r7   r8   r9   r  r5   r3   r2   ParforGufuncCompilerr  %  s    
	r3   r  )pipeline_classz5finished create_gufunc_for_parfor_body. kernel_sig = )wr   rq   rr   rv   rG   rp   r}  r   r   r   r   rN   r~   r{   r|   r   r   rn   ro   get_parfor_reductionsr   r   sortedra  r[  rs   r)   r   r   NamedUniTuplerk  rQ   PARFOR_MAX_TUPLE_SIZEr   r   r   Tuple
NamedTupler  warningswarnr    replace_var_with_arrayr   r  rx  r  r   r  r   r   r   r   r   hexhashreplacejoinr   r   r   r   r   rF  r   Argr  FreeVarr  
containersBaseNamedTuplesplitinstance_classr"   r7   r_  fieldsr   execr   run_frontendru   r~  valuesrF   r   r   r   clearrw   r  r  number_domainformatr   Constr   coretypingr   r   r  r  rz  r{  r  metadata
hoist_infoidrr  Blockr|  r   r\  r   noaliasr   CompilerBase
compile_ir)ir?   r   ro   r   r   r   localshas_aliasesr   rx   rG   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_namerN   
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_labelrw  rs  r  rF   r0   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                                                                                                            r2   r   r   #  s   , "78




C 		&**+I	V&&'J393D3DE3DaA$$))3DL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 $& "$!#"+gu~~.*WeFYFY2Z!--K!--K&">">>?>!#;' 5<S8T T,33MB"))-8 >@G*=9'1,')4& ( /A'+&&r*-GUEUEU1V "--K!--K&">">>?>!#;' 5<S8T T,33MB"))-8=?G*=9'1,')4Q& ( /A'+&&r*(//3] ^ 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##$		&
  B'2,S$wr{2CD  
 ;HH-Q$WQZ0-KH+8>+IK+IQgaj+IKNbbN" +.#^4 i,K,9:MqZ]MM:&MH./0S''{6*ENN,@,@A  !3F!;G!CD  !3F!;< 1 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 jj3.D1AACGG
 %D &499Y-OYjmY-O#PPPJ9~" c!
e
u Bx M*+
;v#68L8LM6$6v$>>,-/<V/DEGLM NJ ,
 ?
>Qf33e;;
CC
 7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 8 $GaK(F& J )	v)'23)* 9~& #	#
 9%& '' -- 	.
	 % %%JN+F& J ,h
Z(G$!3G!<<uDGYZaGbbehhhJ )e
 
Q'f
 (-(**J7S))beopsettw|||Jbeopsettw|||Jfz#.&')/02<S/BDHI 	I
 8 %%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__&	c&!'!2!2!8!8!A!A$!L!Q!QL ' 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/FQ*8E*BI$$Q' 0"%inn&6"7.3	  +*4	  '   188GGIs+-? -B G 1J 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$valrP   r  )rw   r)   r   r  r  rN   rG   rF   r  r   r   rA  r   r  r  r   r   r   r   ra   r   r*   replace_var_with_array_internalrv   r}  )varsrs  ro   r   r  r0   rG   rF   
const_node	const_varconst_assignval_varsetitem_nodes                r2   replace_var_with_array_in_blockrv  D  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 r3   c                 Z    |j                         D ]  \  }}t        | |||      |_         y r(   )r   rv  rw   )rp  r}  ro   r   rw  rs  s         r2   ro  ro  `  s)    !)u4T5'9U
 *r3   c                     t        | |||       | D ]=  }||   }|j                  |d        t        j                  j	                  |dd      ||<   ? y )NrP   r  )ro  popr   r   r   )rp  r}  ro   r   r   el_typs         r2   r	  r	  d  sM    #D)WiHAt^^))&!S9
 r3   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 = ri   	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   ry   r   rN   get_constantr   rA  )r   rk   r?   s    r2   
load_rangez(call_parallel_gufunc.<locals>.load_range  s;    a ??166**''Q77r3   rP   z'call_parallel_gufunc loop_ranges[{}] = zloop range[{}]: %d %d (%d)
   z%Parfor has potentially negative start
dim_starts)sizerN   	dim_stopsget_parallel_chunksizerW   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offsetrL  resrm   r   r?   s        r2   load_potential_tuple_varz6call_parallel_gufunc.<locals>.load_potential_tuple_var6  sQ     %%4Q7Hfooh/G''8CJ??1%%r3   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)Qrk   rm   rj   r|  r}  r   rq   rr   rJ   return_typerecvrpysigr	   normalize_signaturelibraryget_functionrn   llvm_func_namerN   _ensure_finalizedr   r   r  r
   printfllvmliter   IntTypePointerTyper   r   ra   rA  r  rs   get_abi_sizeofry  signedr   sextr9  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  rQ   booleanget_data_typeOptionalcastBooleanr_  r   r   rS   get_null_valueactive_code_libraryadd_linking_libraryr   getvar)ir?   cresr   	outer_sigr  r  r   r   r   
redarrdictrv   r   rx   r   r|  r}  rJ   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_spacerf   
debug_flagscheduling_fntydo_schedulingr  r   r   ninoutsr  all_argsnum_argsnum_inpsarray_stridesrv_to_arg_dictrn  r  atydstaryr  r   rM   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_ptrrm   rk   si   `            `                                                                                         @@r2   r   r   k  s2    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^'NtT::!LL1E99 <<h/D99 <<h/D{{4%7;;((Q()*	+
 	dGKK	)0)=)=ekk1)M(NP 	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]	^
H #++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DGqwz!}112GGD7|H)nx'G&( 6?x5HI5H(+5HIGSH8}H3x!|H!!JJL D MMM'//',,u"5zBDI--ejj+FGN8_qklQkk$!5!5ejj!a%!H IJ<)'$$S)'7C@C**7CKKJG3w<($$WQZ0 )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|,A!((4 -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 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 "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%:;$$&1VFW-A-A%**a-P,QRgll=17>>!3DE '
 33DLLAU
H 
H| E2 Js   29AQ%%AQ3AQ#QAQ)Zrp   r5  r   r  r  dataclassesr   llvmlite.irr  re   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   numba.core.typingr   r   numba.parfors.parforr   numba.core.errorsr    r!   r"   r#   #numba.parfors.parfor_lowering_utilsr$   Lowerr&   r+   r@   r   r   r   r   r   r  r  r
  r  r  r   rt  rx  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r   rv  ro  r	  r   r5   r3   r2   <module>r     s[        &      E E    ( (  8  F(.. */R-j
   !@HE} E
"
J$
L	 6r!FCJ$A <E|v$
 D48@
2 h9
8Y _\B8V:RBr3   