
    J/Ph@V                    T   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*j4                  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[dS )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                   8     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                     t          |t          j                  rt          | |           d S t	                                          |           d S N)
isinstancer   Parfor_lower_parfor_parallelsuper
lower_instselfinst	__class__s     ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/parfors/parfor_lowering.pyr.   zParforLower.lower_inst2   sK    dFM** 	%"4.....GGt$$$$$    c                     dS )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	     tr4   )__name__
__module____qualname____doc__r.   propertyr7   __classcell__r2   s   @r3   r'   r'   -   s]        + +% % % % %   X    r4   r'   c                 R    |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 ]3}t          j
        rt          d|           |                     |           4|j        D ]?}||vr9||         }t+          j        |
||	          }|                     |j        |           @i }i }t2          j        j                            ||j        || j        ||           t          j
        r t          d|           t          d	|           |j        J t2          j        j                            ||j                  }|j         |j!        }}t          j
        r t          d|           t          d|           tE          |          }i }g }|dk    rC|j        j        }
|j        j        }	tG          | |
|	          }|$                    t2          j%        j&        j'        j(        tS          t2          j%        j&        j'        j(                  d          }|*                    |+                    |g           tX          j-        d          }t]          |          D ]z}||         }| j        j        |         }t+          j        |
||	          }t_          |          }|j0        }t          j
        r5t          d||||tY          j1        |          |t          |                     te          |tX          j3        j4                  r|j5        dz   } nd} |$                    tJ          j6        to          tJ          j6                  tY          j8        tX          j-        |           fdtY          j1        |          i          }!|g}"te          |tX          j3        j4                  r|*                    t*          j9        :                    |d|	          tY          j8        tX          j-        |j5                  d          }#t]          |j5                  D ]Y}$|*                    t*          j9        ;                    |#|$d
|	          tX          j-        d          }%|"<                    |%           Z|=                    |"d          }&|j>        ?                    |          }'|@                    |'tY          j1        |                    }(|+                    |!|&|(g          })|*                    |)|d          }*|*||j        <   |<                    |*           ||         jA        }+|+
te          |tX          j3        j4                  r|$                    tJ          jB        to          tJ          jB                  tY          j8        tX          j-        |j5                  |fdtY          j1        |          i          },|@                    |+|d          }-|+                    |,|#|-|(g          }.|*                    |.|d           }/|<                    |/           n|@                    |+|d           }/n|}/t          jC        rd!t          |          z   d"z   }0tY          jE        |0          }1|@                    |0|1d#          }2t+          jF        |2|gd
|	$          }3t          tX          jH        ||2j                 ||j                           | j        jI        |3<   t          d%|3           |                     |3           ||j                 }4|J                    |4          }5t          jL        ||5          }6|
M                    d&|	          }7|4||7j        <   |6| j        |7j        <   t          jN        || O                    |j                  |5'          5 }8|P                    |8jQ        |6           |R                    |*|7|/(           d
d
d
           n# 1 swxY w Y   ||jS                                        }9d)|9_T        ||jU        d         jV        j                 }:|jU        dd
         D ]};||;jV        j                 |:k    sJ d*t2          j        j        _W        	 t          | |||||9i t          |          |:|j        
  
        \  }<}=}>}?}@d+t2          j        j        _W        n# d+t2          j        j        _W        w xY wd,g|=z   }=tE          |          }AtE          |=          tE          |          z
  |Az
  }Bt          j
        rPt          d-|=           t          d.|B           t          d/|           t          d0|           t          d1|A           t          |j[        |B|A|=|>|j        |          }Ct          j
        rt          d2|C           d3 |jU        D             }Dt          j
        r%t          d4|jU                   t          d5|D           t          | |<|C|>|=|?|D||||j        |:|j        |@           |dk    rt          ||| ||           |D ]0}E|                     t+          j^        |Ej        |	6                     1|| j        _        t          j
        rt          d7           d
S d
S )8a  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 = c                 6    g | ]}|j         |j        |j        fS r6   )startstopstep.0ls     r3   
<listcomp>z._lower_parfor_parallel_std.<locals>.<listcomp>z  s%    HHHAGQVQV,HHHr4   zloop_nests = loop_ranges = )rH   z_lower_parfor_parallel done)_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   UniTupleExprgetattrstatic_getitemappendmake_tuple_variable
_typingctx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call_parallel_gufunc#_parfor_lowering_finalize_reductionDel)Fr@   r   rC   	typingctx	targetctxrv   orig_typemaprx   r}   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_typrp   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88888.IIoG >)L!Y|44GN FW^0D0DEEEn$G^F &'''


C#E  Pov0#tF<M7N7NOOO"' " "! 	6-u5555!!!!< 0 0&  G$Ew,,B///IK	M66vv}g(/KQ Q Q *k9%%%m[))) =$$$ =/BB %+^V^NN 1000000 >""HGJ!||!'#%gULLL  44(:%ehn&=&OPP 5 
 
  ,,

?
44
" ' $ $ x h	[ h	[A%a(H /9JVE8S11F 3:>>M$*H% 
$!K))#))	 	 	 *en&:;; &Oa/			
 "66X&rx00N5:y99 ek(334 7  M --M *en&:;; 4$||==uz:?CC'  ,     z// 4 4A %G22<D#NN!J- !- ! !I
 "((3333 00$4 1  H
 #66x@@D**%+h:O:O*PPBM2GGJM &  J
 $.GFK j)))%h/8H#j%.*>?? % &+%?%?W.rw77!N5:zGG$ %ek(&;&;< &@ & &N $)#<#<%$' $= $ $L !&

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

  4 426!&c2223333 *GN -+,,,,,- -s   >4b>>c	c		0f f(_ReductionInforedvar_inforedvar_namer   r   
redarr_typr[   T)frozenc           	      <   |                                 D ]\  }}|j        j        |         }|j        j        |j                 }|                    |          }	t          ||         |||||	          }
|
j        j        t          nt          } || |||
           dS )zYEmit code to finalize the reduction from the intermediate values of
    each thread.
    r   N)
itemsrw   rx   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
^+JO<
??;//$(5#!!!
 
 
 "-3? 101 	 	!1;????-@ @r4   c                        e Zd Z fdZ xZS ) ParforsUnexpectedReduceNodeErrorc                 P    t                                          d|            d S )Nz!Unknown reduce instruction node: )r-   __init__r/   s     r3   r  z)ParforsUnexpectedReduceNodeError.__init__  s*    CTCCDDDDDr4   )r8   r9   r:   r  r=   r>   s   @r3   r  r    sA        E E E E E E E E Er4   r  c                 j   |j         j        D ]}t          ||          rnt          ||j        d          r@|j        j        }t          ||||          }|                    ||j	        j
                   net          ||j        d          r@|j        j        }t          ||||          }|                    ||j	        j
                   nt          |          t          | |||j                  r nt          j        r2|j        }|                    | j         d|j         d| d|           dS dS )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     s    '4  #GT22 	9)$0GYY 	9B3G-{ M ]1ABBBB)$0GQQ 	9B3G-{ M ]1ABBBB 34888 )$#.#:< < 	E	 % 
)zGGBKGGGGGG	
 	
 	
 	
 	

 
r4   c                   
 |j          d
|j        j                            
|j                   |                    |j                  }t          j        |j	        |          5 }|j
        }|j        j        D ]}t          ||          rnt          |t          j                  rjt#          
fd|                                D                       r=t'          |||          }|                    |
           |                    |           nt-          |          t/          | |||j                   r nddd           n# 1 swxY w Y   t0          j        r*|j         }	|                    | j         d|	 d|	           dS dS )zFLower non-trivial reduction such as call to `functools.reduce()`.
    #initc              3   .   K   | ]}|j         k    V  d S r)   rX   )ro   var	init_names     r3   	<genexpr>z,_lower_non_trivial_reduce.<locals>.<genexpr>  s*      NNcCH	1NNNNNNr4   Nz: parfor non-trivial reduction r	  )r   rw   rx   
setdefaultr   r   rO   r
   r   rv   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     s    *111IN%%i1GHHH '7'<==		7?,<	=	= j+8 	 	D'66 =T29-- =NNNNT^^=M=MNNNNN=)#wDD  y111""4(((( 7t<<< -VWd'2'>@ @ %              , % 
)zEE'EEE	
 	
 	
 	
 	

 
s   %CEE	E	c                     t          |t          j                  rat          |j        t          j                  rB|                     |j        j                  }|                     ||j        j                   dS dS )zaLower Var->Var assignment.

    Returns True if-and-only-if `inst` is a Var->Var assignment.
    rX   TF)	r*   r   r  r  r   r   rO   r  r  )r@   r1   loadeds      r3   r  r     sj    
 $	"" z$*bf'E'E 11dk&6777t5r4   c                     d }|j         }|j        }|j        }|                    |j        j                  }|| f}t          |j        |t          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   )rv   rt   r   r   r   rO   r   r   r   rb   compile_internal)idxr@   r   r(  rv   ctxr   arg_arrrK   sigr#  s              r3   r   r   +  s}       oG
/C'Jook49::GS>D
K*J

C
CC#tD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                  }
t"          j        r|j        j                            |j                  }t-          j        |j        |gd|j                  }|j        j        }t7          t8          j        ||j        j                 ||j                           |j        j        |<   |                    |           |                    |j                  }||
|j         f}t7          |j!        t8          j"        |	|j!                  }|#                    ||||          }|S )z;Emit call to the ``binop`` for the reduction variable.
    c                 D    |}t          |           D ]}|||         z  }|S r)   r   thread_countrZ   initcr   s        r3   reduction_addz._emit_binop_reduce_call.<locals>.reduction_add?  2    |$$ 	 	ANAAr4   c                 D    |}t          |           D ]}|||         z  }|S r)   r0  r1  s        r3   reduction_mulz._emit_binop_reduce_call.<locals>.reduction_mulE  r6  r4   Nr_   )$operatoriaddisubaddsubimul	ifloordivitruedivmulfloordivtruedivrt   rv   r   r   r   rO   r   r   rG   getr   r   r   rH   rw   rx   r   r   r   r   r.   r[   r   uintpr)  )r  r@   r   r   r5  r8  kernelr+  rv   r   r,  init_varr   rx   arg_thread_countrK   r-  r  s                     r3   r  r  ;  s        	}}mm}M=m=- F /CoG'Jook49::G% &)/33K4KLLH((3D
 
 
	 .(.7J 6 ;<HM"/
 /
 + 	9%%%'7'<==g{';<D
Z9O C ((&#tDDMr4   c                     t          | t          j                  sdS | j        }t          |t          j                  sdS |j        |k    rdS |j        j        | dk    rdS dS )zDIs ``inst`` an inplace-binop and the RHS is the reduction init?
    Fr  T)r*   r   r  r  r   oprM   rO   )r1   r   rJ  rM   s       r3   r  r  t  so     dBI&& u
*Cc27## u
v||u
w|+,,,,,u4r4   c                    | j         j        }t          |t          j                  r	 |                    |          }|j        }|j        j        }||k    }n # t          $ r ||j        j	        k    }Y nw xY w|rH||j        j	        k    r8|
                    |j        j	                  }	|                    |	|           dS dS )z5Fix reduction variable name mismatch due to SSA.
    rX   TF)r   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88M !. > $ <!26G!G  	A 	A 	A "-0@!@		A  	 dk...oodk&677  ; 777t5s   A A43A4c                 z    t           j        rJt          d|||           |dd         D ],}t          d|t          |            |                     -t	          |          |z
  } fd|dd         D             }	t                      }
|	D ]}|r|D ]}|
                    |           |
rt          |
          dz   nd}|	                    d|f           |
                    |           |dz   }|
                    |           i t          d          }|
D ]}|dk    rt          |          |<   |dz  } t          |          }d	|ifd
g }g }d}d}t           j        r0t          d|           t          d|	           t          d|           t          |	|          D ]\  }}|dz   }|rt          fd|D                       }nd}||k    r<|                    t          |gt          |dd                   z                        m|                    |           ||z  }||fS )z&Create shape signature for GUFunc
    r   rQ   Nargumentrx   c                 6    g | ]}|vr |           ndS )rT  )r6   )ro   r  r   r   rx   s     r3   rq   z+_create_shape_signature.<locals>.<listcomp>  s;    jjjZ]#U:J:J  g6666PUjjjr4   r   alatest_alphac                 j    | dk    r||          S dxx         dz  cc<   t          d                   S )Nr   rX  rQ   )chr)r4  	class_map
alpha_dicts     r3   
bump_alphaz+_create_shape_signature.<locals>.bump_alpha  sE    66Q<~&&&!+&&&z.1222r4   r6   rK   classesthreadcount_ordinalc              3   0   K   | ]} |          V  d S r)   r6   )ro   r4  r]  r[  s     r3   r  z*_create_shape_signature.<locals>.<genexpr>  s/      CC!ZZ955CCCCCCr4   )r   rz   r{   r|   r   setr<  maxinsertordrZ  ziptupler   list)r   r   r   rK   r   r   rx   r   
num_inoutsr^  	class_set_class	max_classthread_num_classalphabetnr_  gu_singu_soutcountsyms_sinclsargdim_symsr\  r]  r[  s   `    ``                 @@@r3   r   r     s     Q'^T5QQQabb 	Q 	QA*aa*;*;Aw*O*O*OPPPPT^+JjjjjjjaefgfhfhaijjjGI ! ! 	! ! !a    &/6I""QINN1yl###MM) 1}MM"###I3xxH  
q&&h--9Q<q=8h-- 8,J3 3 3 3 3 FGEH :fdi!!!#%8999&& ! !S	 	CCCCCsCCCCCHHHJ MM%!4 5Xabb\8J8J JKKLLLLMM(### HHGr4   c                 ^    t          | j                  D ]\  }}t          d|d|           d S )N    rD   )	enumerater   r{   )blockr   r1   s      r3   _print_blockrz    s@    UZ(( $ $4fad####$ $r4   c                 |    t          |           }|D ])}| |         }t          d|           t          |           *dS )z%Pretty-print a set of IR blocks.
    zlabel: N)wrap_find_topor{   rz  )	body_dict
topo_orderlabelry  s       r3   _print_bodyr    sU      	**J  % iU r4   c                 2   |                                  }t          |                                          }t          |                                          }||         j        }||         j                            t          j        ||                     |S r)   )	ry   minkeysrb  rH   r   r   r   Jump)	loop_bodyblocksfirst_label
last_labelrH   s        r3   wrap_loop_bodyr    su    ^^Ffkkmm$$KV[[]]##J


 C
:""27;#<#<===Mr4   c                     t          |                                           }| |         j        d d         | |         _        d S )NrV  )rb  r  r   )r  r  s     r3   unwrap_loop_bodyr    s=    Y^^%%&&J!*:!6!;CRC!@Ijr4   c                     | |v rdS | |v r,|                     |            |                    |            dS |                     |            dS )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)r<  remove)a_defdef_oncedef_mores      r3   add_to_def_once_setsr    sa     	(		UUr4   c                    |                      t          j                  }|D ]}|j        j        }t          |||           |j        }	t          |	t          j                  r.t          |	j        t          j
                  r|	j        j        ||<   t          |	t          j                  r/|	j        dk    r$|	j        j        |v r|	j        j        |	j        f||<   t          |	t          j                  rm|	j        dk    rb|	j        j        |v rT||	j        j                 \  }
}|
|v r*||
         }t!          ||          st          |
||           nt          |
||           t          |	t          j                  r`|	j        dk    rU|	j        D ]M}t          |t          j                  r|j        }||         }t'          |dd          rt          |||           NdS )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   rJ  attrr   r   rK   r   r   )ry  r  r  getattr_takenrx   module_assignsassignments
one_assignr  rM   base_obj	base_attrbase_mod_nameargvaravtypes                  r3   compute_def_once_blockr    s    ""29--K! 0E 0E
!&UHh777c29%% 	; #)W%788 ;(+	(:u%c27## 	>)(;(;	RZ@Z@Z$'INCH#=M% c27## 	C&(8(8SX]m=[=[ #0">Hi>)) !/x 8$]I>> G )8XFFF %XxBBBc27## 	E&(8(8 ( 
E 
Efbf-- )#[F  69e44 E )8DDDa0E 0Er4   c                 `    t          |           }t          |          }t          |            |S r)   )r  r   r  )r  r  r~  s      r3   r|  r|  S  s0    I&&F ((JYr4   c           
         t          |           }|D ]t}| |         }t          ||||||           |j        D ]N}	t          |	t          j                  r2t          |	j        |||||           t          |	j        |||||           OudS )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  r   r*   r   r+   r   compute_def_once_internalr  )
r  r  r  r  rx   r  r~  r  ry  r1   s
             r3   r  r  Y  s      	**J v v%  	uh-R`aaaJ 	v 	vD$.. v&t(M[bdrsss)$.(Hm]dftuuu	vv vr4   c                 r    t                      }t                      }i }i }t          | |||||           ||fS )zRCompute the set of variables defined exactly once in the given set of blocks.
    )ra  r  )r  rx   r  r  r  r  s         r3   compute_def_oncer  m  sD     uuHuuHMNi8]GUcdddXr4   c                 r    t          | t          j                  sJ |                    | j                   | S r)   )r*   r   r   r<  rO   )r  varsets     r3   	find_varsr  w  s3    c26"""""
JJsxJr4   c                    | j         j        |v r:|                    | df           t          j        dk    rt          d| d           dS || j         j                 }t                      }t          | j        t          |           d |D             }	||	z  }
|
                    |          }||
z  }t          j        dk    rt          d| d|d	|           t          |          d
k    r}t          | j        d |          rgt          j        dk    rt          d| |           |                    |            t          |t          j        j                  s|| j         j        gz  }dS t          |          d
k    r9|                    | df           t          j        dk    rt          d| d           n8|                    | df           t          j        dk    rt          d| d           dS )Nzstored arrayrQ   Instructionz9could not be hoisted because the created array is stored.Fc                 ,    h | ]\  }}|j         j        S r6   )r  rO   )ro   assgn_s      r3   	<setcomp>z"_hoist_internal.<locals>.<setcomp>  s!    AAA5<$AAAr4   z_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   rz   r{   ra  r   r  r  
differencer   r   r*   r   r   r   )r1   dep_on_param
call_tablehoistednot_hoistedrx   stored_arraystarget_typeusesunhoistableuse_unhoistdiffs               r3   _hoist_internalr  |  s   {=((D.1222!Q&&-'bcccu$+*+K55DTZD111AA[AAAK$K??<((DKD"" $wEEE
4yyA~~'$*dJ??~!Q&&*D+>>>t+u~';<< 	/T[-..Ltt99q==l3444%**mT+Z[[[j1222%**mT+XYYY5r4   c                 R   |j         D ]}t          |t          j        t          j        f          r`|                     |j        j                   t          |j	        j                 dd          r                    |j	        j                   t          |t          j                  r/t          | |j                   t          | |j                   t          |t          j                  r|j	        fd}t          t          j                  rj        dv rj        D ]} ||           4j        dk    rj        D ]}|D ]} ||           [j        dk    r4t)          j                  d j        D             z   D ]} ||           d S )Nr  Fc                     t          | t          j                  s
J             t          | j                 dd          r                    | j                   d S d S )Nr  F)r*   r   r   r   rO   r<  )itemitemssetrM   rx   s    r3   add_to_itemsetz+find_setitems_block.<locals>.add_to_itemset  sb    !$//44444749-y%@@ ,LL+++++, ,r4   )build_tuple
build_list	build_set	build_mapr   c                     g | ]
}|d          S )rQ   r6   )ro   xs     r3   rq   z'find_setitems_block.<locals>.<listcomp>  s    1H1H1H1!A$1H1H1Hr4   )r   r*   r   StaticSetItemSetItemr<  r  rO   r   r  r   r+   find_setitems_blockr   find_setitems_bodyr  r  r   rJ  r   rg  rK   rS   )	setitemsr  ry  rx   r1   r  r  pairrM   s	    ` `    @r3   r  r    s   
  -  -dR-rz:;; 	-LL)***
 wtz/EBB .TZ_---fm,, 	-(DOWMMMx4>7KKKKbi(( 	- *C, , , , , , ,
 #rw'' 
-6GGG #	 - -&t,,,,-V{** #	 1 1$( 1 1D*N4000011 Vv%% $SX1H1H1H1H1H H - -&t,,,,A -  -r4   c                 ^    |                                 D ]\  }}t          | |||           dS )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  rx   r  ry  s         r3   r  r    sF     ")) @ @uHhw????@ @r4   c           	      0   t          | t          j                  r{t          | j        t          j                  r\| j        j        dk    rL| j        j        j        |v r9|| j        j        j                 }|dt          gk    rt          | ||||||          S dS )Nr   r   F)
r*   r   r  r  r   rJ  r   rO   r   r  )r1   r  r  r  r  rx   r  	call_lists           r3   empty_container_allocator_hoistr    s    4## H4:rw''H


**tz34	"%%"4z7#.H H H5r4   c                    t          j         |           }g }g }t          ||          \  }}t          |          \  }	}
t                      }t                      }t	          ||||           t          t          |                              |                    }t          j        dk    rt          d|d|d|d|d| 
  
         |D ]}t          |||           |                                D ]X\  }}g }|j        D ]@}t          |||	||||          rt          |t          j                  r%|j        j        |v rt'          |||	||||          rWnt          |t(          j                  rg }t          j        dk    r#t          d           |                                 |j        j        D ]k}t          |||	||||          rt          |t          j                  r$|j        j        |v rt'          |||	||||          rV|                    |           l||j        _        |                    |           B||_        Z||fS )NrQ   zhoist - def_once:z	setitems:z	itemsset:zdep_on_param:zparfor_params:r   )ry   r  r   ra  r  rg  r  r   rz   r{   r  r   r   r  r*   r   r  r  rO   r  r   r+   r~   r   r   )parfor_paramsr  rx   wrapped_blocksr  r  r  r  r  r  reverse_call_tabler  r  sir  ry  	new_blockr1   new_init_blockib_insts                       r3   hoistr    s   9]++LGK *)W==Hh'5n'E'E$Z#uuHuuHx9g>>>L))44X>>??L""!8[(KQY[jlx  {K  MZ  	[  	[  	[ 5 5R84444!))    u	J 	# 	#D.t\:#*K(L L 6D"),, 61AX1M1M"4z#*K(L L  	
 D&-00 6!#)Q..(OOOIIKKK#3 3 3G6w"G['8M M 	% $Wbi88 %+x77*7L*+2K+35 5 % %"))'2222'5$T""""

Kr4   c                 B    t          | t          j        j                   S r)   )r*   r   r   r   )redtypes    r3   redtyp_is_scalarr    s    '5>#78888r4   c                     d}t          | t          j        j                  r|| j        z  }| j        } t          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77r4   c                     t          | t          j        j                  sJ t          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    sB     k5>#788888> 1;3C[EWXXXr4   c                 z    t          |           }|                                D ]\  }}||k    r||         ||<   |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   )namesrx   outdictr  ys        r3   legalize_names_with_typemapr  $  sH     U##G $ $166 GAJNr4   c                 ^    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*++ 6Q;;7NHr4   c
           
      Z,  ef t           j        dk    rt          d           |j        j        }
t          j        |j                  }t          |           t          |j	                  }d |j	        D             }|j
        }t          j        j                            ||          }| j        j        t          j        j                            | j        ||| j        j                  \  }}t)          t+          t-          |          t-          |          z
  t-          |          z
                      }t           j        dk    r|t          d|dt/          |                     t          d|dt/          |                     t          d|dt/          |                     t          d|dt/          |                     g }i }i }d	}g }|D ]}|         }t1          |t2          j                  st1          |t2          j                  r|j        }|j        }|t           j        k    sJ g }t?          |          D ]O}d
tA          |          z   }|!                    |           |!                    |           ||f||<   |dz  }||<   P|||<   |!                    |           t1          |t2          j"                  st1          |t2          j#                  r|j        }|j        }|t           j        k    sJ g }t?          |          D ]U}d
tA          |          z   }|!                    |           |!                    |           ||f||<   |dz  }||         |<   V|||<   |!                    |           |!                    |           |}t           j        dk    rt          d|dt/          |                     |	$                    t-          |                    }	|	D ])} d| z  }!tK          j&        tO          |!|
                     *tQ          |	|| j        j                   g }"g }#|D ]m}$|$dz   }%|"!                    |%           tS          |$                   }&|#!                    |&           tU          |&          }'|%v r|%         |'k    sJ h|'|%<   n||z   |"z   }t           j        dk    rlt          d|dt/          |                     t          d|dt/          |                     t          d|dt/          |                     tW          |           tY          ||z   |z             ft           j        dk    r>t          dt)          f-                                          dt/          f                     tY          |          eefd|D             }(t           j        dk    rt          dt)          e-                                          dt/          e                     t          d|(dt/          |(                     |D ]=})t          d|)           t          d|)         dt/          |)                              >fd|D             }*fd||z   D             |#z   }+t           j        dk    r t          d|*           t          d|+           t]          |f           |},ffd|D             }|}-g }d}.t?          t          |-                    D ]v}/|.rW|/t          |          k     rDt1          |*|/         t2          j/        j0                  r|!                    |-|/         dz              [|!                    |-|/                    wt]          |e           tc          |          }0te          d|0          }1t           j        dk    rt          d|dt/          |                     dtg          ti          |                    5                    d d!          z  }2t           j        rt          d"t/          |2          d|2           d#}3|3d$|2z   d%z   d&6                    |          z   d'z   z  }3tn          t          d(}4|-                                D ]"\  }5}6|5         }7|3d)f|5         z   z  }3t1          |7t2          j#                  st1          |7t2          j                  rd*}8nd}8|8rtq          tr          | j        |5          }9d+}:t           j        rt          d,|9t/          |9                     |9t1          |9tt          j;                  rV|9j<        d-k    rKtq          tr          | j        |9j=                  }:t           j        rt          d.|:t/          |:                     nWt1          |9tt          j>                  r=|9j?                 }:t           j        r$t          d.|:t/          |:          |:j?                   |:t1          |:tt          j@                  st1          |:tt          jA                  r<|:jB        };t           j        rt          d/|;t/          |;                     |;|4|:j?        <   nt1          |:t2          jC        jD                  r_|:j?        E                    d0          d	         }<t           j        r)t          d1|<|:jF        t/          |:jF                             |:jF        |4|<<   n@t           j        rt          d2           t          d3tA          |5          z   |5j                  |3d4|7jF        jH        z   d0z   z  }3t          |6|7jJ                  D ]\  }=}>|3|>d5z   f|=         z   d6z   z  }3n?|3d7d&6                    ffd8|6D                       z   z  }3t          |6          dk    r|3d6z  }3|3d9z  }3$t?          t          |                    D ]F}/|.rBt1          |*|/         t2          j/        j0                  r|3d)|-|/         z   d:z   ||/         z   d9z   z  }3Gd;}?t          |"          d	k    r|3d)|?z   d4z   z  }3|3d<z  }3t          |"|          D ]s\  }%}$|3d)f|$         z   d5z   f|%         z   d=z   |?z   d>z   z  }3t           jK        r?|3d?z  }3|3d@f|$         z   d6z   f|$         z   dAz   z  }3|3dBf|%         z   d6z   f|%         z   dAz   z  }3tt?          |          D ]X}@t?          |@dz             D ]}A|3d)z  }3|@}B|3dC|(|@         z   dDz   tA          |B          z   dEz   tA          |B|z             z   dFz   z  }3Yt           jK        rSt?          |dz             D ]}A|3d)z  }3|3dGz  }3t?          |          D ]}@|3dH|(|@         z   dIz   |(|@         z   d6z   z  }3 |3d9z  }3t?          |dz             D ]}A|3d)z  }3|3|1dJz   z  }3t          |"|          D ]V\  }%}$t           jK        r"|3dKf|$         z   d9z   z  }3|3dLf|%         z   d9z   z  }3|3d)f|%         z   d=z   |?z   dMz   f|$         z   dNz   z  }3W|3dOz  }3t           j        r=t          dPt/          |3          dN|3           t          dQ|4t/          |4                     i }Ct          |3|4|C           |C|2         }Dt           j        rt          dRt/          |D          dN|D           t          jN        |D          }Et           j        r]t          dSt/          |E                     |EO                                 t          dTt/          |                     tW          |           tc          |EjP                  }Fi }G|1gt+          fQ                                          z   |(z   }H|F-                                D ]1\  }=}$|=|Hvr(|j        jR        S                    |=|
          j?        |G|=<   2t]          |EjP        |G           t           j        r#t          dU           |EO                                 t2          j/        0                    |ddV          g|*z   }It           j        rt          dWt/          |I          dN|I           t          |EjP                  dz   }Jt          ||J          }t          |          dz   }Kt           jK        r|-                                D ]\  }L}M|M                                }N|NV                                 |Mj        }
|MjR        }O|MjW        D ]r}P|N!                    |P           t1          |Ptt          jX                  r?|PjY        j?                 t2          jZ        vrRdX[                    |PjY        j?                  }Qt3          j\        |Q          }R|OS                    dY|
          }Stu          jX        tu          j]        |Q|
Z          |S|
[          }T|R|Sj?        <   |N!                    |T           tu          j^        |S|PjY        gd+|
\          }U|N!                    |U           t          j_        j`        a                    t2          jb        |Sj?                 |PjY        j?                           }V|V| j        j        |U<   t|N||L<   t           j        rt          d]           tW          |           t          |          }Wt          |||W          \  }X}Y|EjP        t          |EjP        f                                                   }Z|ZjW        d+d^         |Xz   |ZjW        d^         gz   |Z_W        t          |           | jh        d_         }[|X|Yd`|[ji        |jj        <   t           j        rt          da           tW          |           |EjP        -                                D ]\  }L}Mt          |MjW                  D ]e\  }}Pt1          |Ptt          jX                  rD|PjY        j?        |1k    r3|Pj        }
|MjR        }Otu          jl        |O|
          }\|MjW        d+|         |\_W        |MjW        |dz   d+         |M_W        t          |f                                          }]|\!                    tu          jm        |]|
                     |-                                D ]\  }^}_t          |_|O          |EjP        |^<   t          |f                                          }`|M|EjP        |K<   |\|EjP        |L<   |EjP        |`         !                    tu          jm        |K|
                      ng t           j        r#t          db           |EO                                 t          |EjP                  |E_P        t          |EjP                   t           j        rCt          dc           |EO                                 t          dd|           t          de           |jq        }a|s"t           j        rt          df           d*|_q        t          |EjP                    G dg dht          js                  }bt          jt        |||E|It2          jb        |||bi          }c|a|_q        t          t2          jb        g|IR  }dt           j        rt          dj|d           |c|,|d|+|fS )ka~  
    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_bodyc                 &    g | ]}|j         j        S r6   )r   rO   rn   s     r3   rq   z2_create_gufunc_for_parfor_body.<locals>.<listcomp>]  s    EEEaA$)EEEr4   z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 = c                      g | ]
}|         S r6   r6   )ro   r   ind_dicts     r3   rq   z2_create_gufunc_for_parfor_body.<locals>.<listcomp>  s    <<<!(1+<<<r4   zind_dict = zlegal_loop_indices = zpd = z
pd type = c                 :    g | ]}t          |                   S r6   )r  ro   r   rx   s     r3   rq   z2_create_gufunc_for_parfor_body.<locals>.<listcomp>  s&    HHHQ$WQZ00HHHr4   c                      g | ]
}|         S r6   r6   r  s     r3   rq   z2_create_gufunc_for_parfor_body.<locals>.<listcomp>  s    KKKQgajKKKr4   znew param_types:znew func_arg_types:c                      g | ]
}|         S r6   r6   )ro   r   
param_dicts     r3   rq   z2_create_gufunc_for_parfor_body.<locals>.<listcomp>  s    :::qZ]:::r4   Fparam__sentinel__zlegal parfor_params = z__numba_parfor_gufunc_%s-r  zgufunc_name  zdef z(sched, z, z):
)r   r   rw  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 = (c                      g | ]
}|         S r6   r6   )ro   r  r  s     r3   rq   z2_create_gufunc_for_parfor_body.<locals>.<listcomp>X  s    -O-O-Ojm-O-O-Or4   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 bodyrV  parfor_diagnostics)r  r  zAfter hoistingz#gufunc_ir last dump before renamingzgufunc_ir last dumpr   rx   z(No aliases found so adding noalias flag.c                       e Zd Zd ZdS )<_create_gufunc_for_parfor_body.<locals>.ParforGufuncCompilerc                 N   ddl m} t          j        } |d          }|                    | 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AAAAA-C122B#&#D#DTZ#P#P I18999!QQRVR\]]OI_3444KKMMM4Kr4   N)r8   r9   r:   r  r6   r4   r3   ParforGufuncCompilerr  <  s#        
	 
	 
	 
	 
	r4   r  )pipeline_classz5finished create_gufunc_for_parfor_body. kernel_sig = )ur   rz   r{   r   rH   ry   r  r   r   r   r   r   r   r   r   rw   rx   get_parfor_reductionsr   r   sortedrg  ra  r|   r*   r   r   NamedUniTuplerq  rR   PARFOR_MAX_TUPLE_SIZEr   r   r   Tuple
NamedTupler  warningswarnr!   replace_var_with_arrayr   r  r  r  r   r   r   r   r   r   hexhashreplacejoinr   r   r   r   r   rJ  r   ArgrO   r  FreeVarr  
containersBaseNamedTuplesplitinstance_classr#   r8   re  fieldsr   execr   run_frontendr~   r  valuesrG   r   r   r   clearr   r  r  number_domainformatr   Constr   coretypingr   r   r  r  r  r  r  metadata
hoist_infoidrx  Blockr  r   rb  r   noaliasr   CompilerBase
compile_ir)gr@   r   rx   r   r   r   localshas_aliasesr   r   rH   r  
parfor_dim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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_name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_labelr  ry  r  rG   r1   strvalr   r   
assign_lhs
print_noder-  r  r  r  start_blockdiagnostics
prev_blockbody_first_labelrp   bbody_last_label	old_aliasr  kernel_func
kernel_sigr  r  sg     `                                                                                                  @@r3   r   r   :  s   , ""7888


C 	&*++I	V&''JEE63DEEEL MM])<<V]SSNn$G%*]%9%O%O0H&J &J"NN   	! 	!" "M "" -d=6I6IJJJ!>3^8L8LMMM -d=6I6IJJJ!>3^8L8LMMM $& "$!# .4 .4"+gu~.. *	4*WeFY2Z2Z *	4!-K!-K&">>>>>!#;'' 5 5 5<S8T8T T,33MBBB"))-888 >@G*=9'1,')4&& /A'+&&r****-- 	4GUEU1V1V 	4 "-K!-K&">>>>>!#;'' 8 8 5<S8T8T T,33MBBB"))-888=?G*=9'1,')4Q&&.@'+&&r****(//33330M""4mS$}J]J]^^^ S0011E < <=?CD 	0c::;;;;5)Wgn6NOOO N 	% 	%Flc"""-gcl;;##L111'55	'>>3<9,,,,,$GCLL "N2^CM"" -d=6I6IJJJsD4F4FGGGnid9oo>>>I -]^-KNa-acjkkJ""  ""$ $	 	 	 +<AAH<<<<|<<<""mVHNN$4$455sDNNKKK##$$		& 	& 	&
   	E 	EB'2,S$wr{2C2CDDDD IHHH-HHHKKKKK=>+IKKKNbbN"" +...#^444 i,,,K::::M:::M&MH.//00 = = 	=S''''{6*EN,@AA (  !3F!;G!CDDDD  !3F!;<<<< i***,Y77'8KLLM""$		! 	! 	! -DLL!!#s++-K Cnd;//kBBBJ &;&ii..0289 9J ''F
 :??AA : :7#fz'222
x!122 	x!455	III .	" ^W_gFFH"O% =k8T(^^<<<#x11 	KK6))&+NGOX]&[&[O- Z0/4CXCXYYY"&11 K&-hm&<O- K0/"?33_5IK K K*	:: N
;;N*0D- 9gtT$ZZ88837F?/001A1PQQ N'6';'A'A#'F'Fq'I$- Dg'7-<"?#ABBD D D 0?/MF+,) NLMMM#$Cc'll$R%,[2 2 2%("9"BBSHHJ$'	8?$C$C H H jj3.D1AACGG

H &499-O-O-O-OY-O-O-O#P#PPPJ9~~"" c!
e

M**++ N N 	N
;v#68LMM 	N6$6v$>>,-/<V/DEGLM NJ ?
>Qf33e;;
CC
 77 U USfz#.c?#%()+?@BGH 	H
) 	U[[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 $$ . .GaK(( 	! 	!F& JJ	v)'23)* 9~~& #	#
 9%& ' '' -- 	.

 % JN++ 	! 	!F& JJh
Z(( 	i 	iG$!3G!<<uDGYZaGbbehhhJJe
 
Q''  f

-(**J77 I IS) 	}beopsettw|||Jbeopsettw|||Jfz#.&')/02<S/BDHI 	I

%%J /otJ//zBBBif...EVU###$K F[ 1 14EEE%k22I i111i111I #9#344IL#_Z  !!"$67N__&& R R	c&&!'!2!8!A!A$!L!L!QLi&555 .///...1c# # $&12  ##$$		  	  	  ,I,<==A %Y0FGGIy))A-I %  )%OO-- 	) 	)LE5

IOO)CKE
 ? ?  &&&dBI.. ?t{/08KKK  $]]4;+;<<F"'"5f"="=K..c::C!#C1P1P1P253"@ "@ "@J(3GCH%$$Z000 "$T[/A$TW!X!X!XJ$$Z000*+55ej+238+<+24;3C+DF FC <?GN,Z8(Ie  !!!I#I..N 	7NSSG["3y'7'<'<'>'>#?#?@K"',w6+:J2:N9OOKY "#78K4;8C)E )EK69%  I "(..00 # #u ,, !	 !	GAtI  #';#3}#D#Dh  XeS11
"'*RaR.
"ZA/
#&y~~'7'7#8#8  !!"'*:C"@"@AAA (oo// C CFQ*8E*B*BI$Q''"%inn&6&6"7"7.3	 +*4	 '  188GIs++- - - 3444$Y%566I	 !!! "#$$$gui!!!I ! 	><===i.///    x4    %
+- - -K EM5:;(:;;;J SEzRRRZA[[[r4   c           	          g }|j         D ]}t          |t          j                  r|j        j        | v rv|j        }|j        j        }t          j        d|          }|	                    d|          }	t          j        ||	j        <   t          j        ||	|          }
|                    |
           |	                    d|          }||j        j                 ||j        <   |                    t          j        |j        ||                     t          j        |j        |	||          }t          t          j        t          j                            ||j        j                 dd          t          j        ||j        j                           ||<   |                    |           t          |t(          j                  r0t-          | d|j        i||           t-          | |j        ||           |                    |           |S )Nr   z$const_ind_0z$valrQ   r  )r   r*   r   r  r  rO   rH   rG   r4  r   r   rE  r   r  r  r   r   r   r   rb   r   r+   replace_var_with_array_internalr   r  )varsry  rx   r   r  r1   rH   rG   
const_node	const_varconst_assignval_varsetitem_nodes                r3   replace_var_with_array_in_blockr  [  s   I
  dBI&& 	V4;+;t+C+C(CK%E!S))J~s;;I&+kGIN#9ZC@@L\***nnVS11G$+DK,<$=GGL!RYtz7C@@AAA:dk9gsKKL&/
EN009I1JAsSSUZU_ahimitiyaz'| '|Il#\***fm,, 	V+D1do2FQZ[[[+D$.'9UUUr4   c                 h    |                                 D ]\  }}t          | |||          |_        d S r)   )r   r  r   )r  r  rx   r   r  ry  s         r3   r  r  w  sD    !)) V Vu4T5'9UU

V Vr4   c                     t          | |||           | D ]D}||         }|                    |d            t          j                            |dd          ||<   Ed S )NrQ   r  )r  popr   r   r   )r  r  rx   r   r   el_typs         r3   r"  r"  {  sk    #D)WiHHH : :At^))&!S99

: :r4   c                 *   	efg  j         f j        eddlm}m} t
          j        rvt          d           t          d|j        |j	        |j
        |j                   t          d|           t          d|           t          d|           t          d|           t          j        |          \  }}|j                            |j        j                  }|\  }} |              |||||d	d
          }|j        }|j                                         t
          j        rt          d||           f fd}t)          |          }t+          |          D ]}||         \  }}} ||          } ||          }|dk    sJ  ||          }|||f||<   t
          j        rPt          d                    |          |||           t/          j        ed                    |          |||           t2          j                            d          }t2          j                            |          }t2          j                            |          }f                    t<          j                  } f                    t<          j                   }!t2          j                            |           }"t2          j                            |"          }#t2          j                            |!          }$t2          j                            |$          }%f!                    t<          j         d          }&f!                    t<          j         d          }'|'j"        }(f#                    |           })|$                    d           |$                    d          }*t
          j        rt          d|j%                   |j%        r| }+|"},|#}-n|!}+|$},|%}-t/          j&        e|+f!                    t<          j         |          d          }.t/          j&        e|+f!                    t<          j         |          d          }/t+          |          D ]}||         \  }}}|j"        |(k    re'                    ||(          }|j"        |(k    re'                    ||(          }|j"        |(k    re'                    ||(          }e(                    ||'          }e)                    |e*                    |.f!                    t<          j         |          g                     e)                    |e*                    |/f!                    t<          j         |          g                     t/          j+        ej,        t2          j        -                    |!g           d          }0t/          j+        ej,        t2          j        -                    t2          j        .                                |!g          d          }1t/          j+        ej,        t2          j        -                    t2          j                            t<          j        j/                  g           d          }2e0                    |2g           }3e0                    |0g           }4t/          j1        ee2                    d|3|3"                    d                              5  t/          j        ed|3           fj3        4                    etj          d           ddd           n# 1 swxY w Y   t2          j        -                    |!|!|!|"|"g          }5t/          j+        ej,        |5d          }6e0                    |6|3f!                    t<          j         |          |.|/g          }7e0                    |1|&g           f!                    t<          j         |dz            }8e6                    |7|8          }9t2          j        -                    |,|!g          }:t/          j+        ej,        |:d           };e0                    |;|9g          }<t/          j&        e|,          }=e)                    |<|=           t
          j        rdnd}>t2          j        -                    |"|!|"|"|!|,| g          }?|j%        rt/          j+        ej,        |?d!          }@nt/          j+        ej,        |?d"          }@e0                    |@f!                    t<          j         |          |.|/|7e7                    |=          f!                    t<          j        |>          g            	fd#|D             }At)          |          }Bt)          |          |Bz
  }Ce fd$ggfd%|d|C         D             |Az   }Dt)          |D          }Et)          |          dz   }Ft/          j&        e|f!                    t<          j        d|Ez             d&          }g }Ge)                    e8                    e7                    |=          |          |           |G9                    f!                    t<          j        |)                     i }Ht+          |E          D ]	}|D|         }I||         }J||         }Ke*                    |f!                    t<          j        |dz             g          }L||Ck    r f:                    |K          fe|I          }Mt/          j;        e|Mj<        |Kj=                  }Nt+          t)          |N                    D ]}O|G9                    |N|O                    e)                    e8                    |Mj>        |          |L           t          |Kt<          j@                  r|J|v r|KjA        t<          jB        k    rfC                    |KjA                  nt2          j                            d          }Pt/          j&        e|P          }Qe)                    |I|Q           e)                    e8                    |Q|          |L           |I|Qf|H|J<   |G9                    f!                    t<          j        f#                    |P                                f:                    |K          fe|I          }Mt/          j;        e|Mj<        |Kj=                  }Nt+          t)          |N                    D ]}O|G9                    |N|O                    e)                    e8                    |Mj>        |          |L           ||Fk     rt          |Kt<          jD                  r |Kj"        }RfE                    e|I|K|R          }In|K}Rt          |Rt<          jF                  sfC                    |R          nt2          j                            d          }Pt/          j&        e|P          }Se)                    |I|S           nct          |Kt<          jF                  sfC                    |K          nt2          j                            d          }Pt/          j&        e|P          }Se)                    e8                    |S|          |L           i }Tg }U|*d         g}Uf!                    t<          j        d|z            |T|*d         <   t)          |          t)          |D          k    sJ t)          |          t)          |          k    sJ t)          |          t)          ||z             k    sJ t)          |          t)          |j        dd                   k    sJ t          ||D|||z             D ]T\  }J}I}K}Vt          |Kt<          jH        jI                  r|Kj=        t)          |V          z
  }nd}t
          j        rt          d'|Jd(|Vd)|Kd*|           |VD ]}Wt
          j        rt          d+|Jd,|K           |J|v r$f!                    t<          j        d          |T|W<   nK f:                    |K          fe|I          }Mt/          j;        e|MjJ        |Kj=                  }X|X|         |T|W<   |W|UvrRt
          j        r1t          d-|Wd.|           t/          j        e|Wd/z   |T|W                    |U9                    |W           |dz   }Vt)          |T          dz   }Yt/          j&        e| |Yd0          }Xe)                    |7|X           d}|UD ]}Wt
          j        rt/          j        e|Wd/z   |T|W                    e)                    |T|W         e*                    |Xf!                    t<          j        |          g                     |dz   }|Edz   t)          |G          z   }Zt/          j&        e| f!                    t<          j        |Z          d1          }[e)                    f!                    t<          j        d|z  |)z            |[           t+          |E          D ]R}|&}\e*                    |[f!                    t<          j        d|z             g          }Le)                    |\|L           St+          t)          |G                    D ]Y}Oe*                    |[f!                    t<          j        d|Ez   |Oz             g          }Le)                    |G|O         |L           Zt/          jK        |          }]t2          j        -                    t2          j        .                                ||"|"|g          }^t/          j+        ej,        |^|          }_fjL        M                    |j                   t
          j        rt/          j        ed2|_           e0                    |_||X|[|]g           t
          j        rt/          j        ed3|_           e0                    |1|4g           t2          j        -                    t2          j        .                                |,g          }`t/          j+        ej,        |`d4          }ae0                    |ae7                    |=          g           |HN                                D ]{\  }b}c|c\  }I}Qe*                    |Qf!                    t<          j        d          g          }de)                    e7                    |d           O                    |b                     |fjL        M                    |j                   dS )5zF
    Adds the call to the gufunc function from the main function.
    r   )build_gufunc_wrapper_launch_threadsmake_parallel_loopzouter_sig = rr   	expr_argsexpr_arg_typesr   FT)cache
is_parforszparallel function = c                     t          | t          j                  r                    | j                  S                     t          j        |           S r)   )r*   r   r   r   rO   get_constantr   rE  )r   rt   r@   s    r3   
load_rangez(call_parallel_gufunc.<locals>.load_range  sC    a   	8??16***''Q7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                 P    g | ]"}                     |         j                  #S r6   )r   rO   )ro   r  r@   
redarrdicts     r3   rq   z(call_parallel_gufunc.<locals>.<listcomp>H  s,    DDDqwz!}122DDDr4   c                     | v r8|          \  }}                     |          }                    ||          }|S                      |           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offsetrc  resrv   r   r@   s        r3   load_potential_tuple_varz6call_parallel_gufunc.<locals>.load_potential_tuple_varM  s]     %%%4Q7Hfooh//G''88CJ??1%%%r4   c                 &    g | ]} |          S r6   r6   )ro   r  r  s     r3   rq   z(call_parallel_gufunc.<locals>.<listcomp>a  s%    III((++IIIr4   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)Prt   rv   rs   r  r  r   rz   r{   rK   return_typerecvrpysigr	   normalize_signaturelibraryget_functionrw   llvm_func_namerO   _ensure_finalizedr   r   r3  r
   printfllvmliter   IntTypePointerTyper   r   rb   rE  r  r|   get_abi_sizeofr  signedr   sextr=  r   gepget_or_insert_functionmoduleFunctionTypeVoidTypebitwidthr   if_unlikelyicmp_signed	call_convreturn_user_excRuntimeErrorrA  loadbitcastr   
make_arrayunpack_tuplestridesr   datar*   r  rR   booleanget_data_typeOptionalcastBooleanre  r   r   rT   get_null_valueactive_code_libraryadd_linking_libraryr   getvar)hr@   cresr   	outer_sigr  r  r   r   r   r  r   r   r   r   r  r  rK   r  	llvm_funcsinsoutinfowrapper_namer  num_dimr   rk   rl   rm   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   ninoutsall_argsnum_argsnum_inpsarray_stridesrv_to_arg_dictrt  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_ptrrv   rt   r  sh   `        `   `                                                                                       @@@r3   r   r     s"    oGoG, , , , , , , ,  ,"###nini.Coy	0 	0 	0,,,k9%%%///nl+++ !4Y??D+))$+*DEEIIC O	4d&+> > >D9LL""$$$ :$lD9998 8 8 8 8 8 +G7^^ . .'NtT
5!!z$qyyyyz$t,A! 	.;BB1EEu  N7$B$I$I!$L$L $. . . [  ##F((00J[,,Z88N##EJ//F$$U[11G((00J[,,Z88N+))'22Kk--k::OQ//D


u{A
.
.CxH((00K MM!

I M5}7KLLL -
#+
$, $'"6"6K#" #"(46 6 6J #'"6"6K#" #"(35 5 5I 7^^ Q Q'NtT:!!LL11E9  <<h//D9  <<h//D{{4%%7;;((Q( ()* *	+ 	+ 	+
 	dGKK	)0)=)=ek1)M)M(NP P 	Q 	Q 	Q 	Q 2  "--%' ' 'M
 2  !5!5!7!7'CC%' ' 'M
 4  !4!4UZ5H!I!I2NN O ,,33K]B77		Wg&9&9$2=2B2B12E2E'G 'G 
H 
H ^ ^w 3[AAA))'<3]	^ 	^ 	^^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ #+227Wgz[e<fgg3  N LL+292F2Fu{T[2\2\2<2;2= > >M
 LL''' %%ek7Q;??J]J77J  {//	JJ5   ,,/*>>K88EMM+u%%%,3!Jk..Wj*g~vVX XO V6w~7F<RT T T  6w~7F<TV V V
 LL  W& &'19mLL!5!5J
", ",-. . . EDDDDGDDDG7||H)nnx'G& & & & & & &( JIIIYxx5HIIIGSH8}}H3xx!|H!!JL    D MMM'//',,u"5"5zBBDIII--ej+FFGGGN8__ 2A 2AqklQkk$!5!5ej!a%!H!H IJJ<<)'$$S))'7C@@C*7CKJJG3w<<(( 1 1$$WQZ0000MM'//#(J??EEEEU233 &	Ae||)u}44 ,,SY777$K//22  !,Wc::c6***goofjAA3GGG'*Fms#$$W%9%9%*gF\F\]`FaFa%b%bcccc-g((--gwDD!.wSXNNs7||,, 5 5A!((4444gooch
CCSIIII8||c5>22 '#&8L!,,wS,GGCC#&L(u}EE3w,,\:::$K//22  )'377c3'''' )em<<3w,,S111$K//22  )'377MM'//#z::C@@@@ LKQ<.K!(!5!5ej!g+!N!NL1y>>S]]****y>>S000000y>>St__,,,,y>>S!3444444!$Y%3S4Z"A "A  S#vc5>/00 	3v;;&AAA! 	M'3
FHc5!LLL 	 	G% 6hZ555e||(/(<(<UZ(K(KW%%-g((--gwDD -gsy#(KK(.q	W%{**) X,1===N7Gi,?gAVWWW""7+++AAA	( ,!#G &wXNNNFMM-(((	A  ! 	PN7Gi$7g9NOOO!7;;((
A' '($) $)	* 	* 	*
 E
 1s=111Ig22J	# #)13 3 3E MM'&&uz1w;3LMM   8__ % %kk%'"6"6uz1q5"I"I!JKKh$$$$3}%%&& - -kk$$JHq 02 234 4 	mA&,,,, !*--D;##HK$8$8$:$:%3Z%/%=> >D 
	'l	K	KB33DLAAA Bw <bAAALLdFE40111 Aw ;R@@@LL!2 3444 "11(+2F2F2H2H>JZ[[ 7! ! ! LL#gll5&9&9%:;;;$$&& F F1VFW-A-A%*a-P-P,QRRgll=117>>!3D3DEEEE33DLAAAAAs   ?8\\
\)\ry   r9  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   rz  r  r  r  r  r  r|  r  r  r  r  r  r  r  r  r  r   r  r  r  r   r  r  r"  r   r6   r4   r3   <module>r)     s           & & & & & &                      E E E E E E E E E E E E E E E E                                         * ( ' ' ' ' '       8 8 8 8 8 8            F E E E E E    (.   */ / /R- R- R-j
       !@ !@ !@HE E E E E} E E E
"
 "
 "
J$
 $
 $
L	 	 	   6 6 6r  ! ! !FC C CJ$ $ $    A A A   <E <E <E|  v v v(    
$ $ $L!- !- !-F@ @ @
 
 
3  3  3 j9 9 9
8 
8 
8Y Y Y     _\ _\ _\B  8V V V: : :RB RB RB RB RBr4   