
    wg                    L   d dl Zd dlZd dlZd dlZd dl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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#m$Z$m%Z% d dl&m'Z' d dl(m)Z) d dl*m+Z+ d d	l,m-Z- d d
l.m/Z/ d dl0m1Z1 d dlm2Z2 d dl3m4Z5 d dl6Z7d dl8Z8d dl9Z	 dZ:d Z;d Z< G d de=      Z>d Z? G d de=      Z@	 	 	 	 d*dZAd ZBd ZCd ZDd ZEd ZFd ZGd ZHd ZId ZJd  ZKe)d!        ZL	 	 d+d"ZMd# ZNd$ ZOd% ZP e
j                  d&       G d' d(e
j                               ZSd) ZTy),    N)typestypingerrorsirrewritesconfigir_utilscgutils)internal_prange)
next_labeladd_offset_to_labelsreplace_varsremove_delsrename_labelsfind_topo_ordermerge_adjacent_blocksGuardExceptionrequireguardget_definitionfind_callnamefind_build_sequenceget_np_ufunc_typget_ir_of_codesimplify_CFGcanonicalize_array_mathdead_code_elimination)compute_cfg_from_blockscompute_use_defscompute_live_variables)impl_ret_untracked)	intrinsic)	signatureListIterInstance)range_impl_map)
make_array)postproc)empty_inferredTc                    | j                   j                         D ]m  }|j                  t        j                        D ]I  }t        |j                  t        j                        s(d}t        j                  ||j                         o y)z8Checks the IR of a callee is supported for inlining
    z-The use of yield in a closure is unsupported.locN)blocksvalues
find_instsr   Assign
isinstancevalueYieldr   UnsupportedErrorr,   )func_irblkstmtmsgs       b/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/numba/core/inline_closurecall.pycallee_ir_validatorr:   4   sn     ~~$$& ANN299- 	AD$**bhh/E--ctxx@@	AA    c                     |  d| }|j                  dd      j                  dd      }|j                  dd      j                  dd      }|S )a  Creates a name for an inlined variable based on the function name and the
    variable name. It does this "safely" to avoid the use of characters that are
    illegal in python variable names as there are occasions when function
    generation needs valid python name tokens..<_>$_v)replace)function_namevar_nameinlined_namenew_names       r9   _created_inlined_var_namerH   >   sY    
 $_AhZ0L##C-55c3?H S)11#t<HOr;   c                   @    e Zd ZdZi dfdZd Zd Zd Zd Zd Z	d	 Z
y
)InlineClosureCallPasszInlineClosureCallPass class looks for direct calls to locally defined
    closures, and inlines the body of the closure function to the call site.
    Fc                 J    || _         || _        || _        g | _        || _        y N)r5   parallel_optionsswapped_processed_stencilstyped)selfr5   rM   rN   rP   s        r9   __init__zInlineClosureCallPass.__init__Q   s'     0#% 
r;   c                    t        j                  | j                        }|j                  d       d}t	        | j                  j
                  j                               }t        d      } |d       |r|j                         \  }}t        |j                        D ]  \  }}t        |t        j                        s!|j                  }	t        |	t        j                        sH|	j                   dk(  sXt#        t$        | j                  |	      }
t#        t&        | j                  |	j(                        }t#        | j*                  ||||	|
      rd} n:t#        | j,                  ||||      rd} nt#        | j.                  ||
|      sd} |rt0        r'|rt3        | j                  j
                         t5        | j                  j
                        } |d       t7        |       |j9                         }|j;                         D cg c]  }|t=        ||   j                        f }}g }t?        |d d      D ]d  \  }}|jA                  |       t#        tB        | j                  ||||   | jD                  | jF                  jH                  | jJ                        scd}f |rtM        | j                         |rt5        | j                  j
                        }|jO                         D ]  }| j                  j
                  |=  tQ        | j                         tS        | j                  j
                        | j                  _        tU        | j                  j
                          |d	       y
c c}w )z&Run inline closure call pass.
        TFrJ   STARTcallzstart inline arraycallc                     | d   S N    )tups    r9   <lambda>z+InlineClosureCallPass.run.<locals>.<lambda>   s
    CF r;   )keyreverseENDN)+r(   PostProcessorr5   runlistr-   items_make_debug_printpop	enumeratebodyr1   r   r0   r2   Expropr   r   r   func_inline_reduction_inline_closure_inline_stencilenable_inline_arraycallr   r   _debug_dumploopskeyslensortedappend_inline_arraycallrN   rM   comprehensionrP   _fix_nested_array
dead_nodesr   r   r   )rQ   ppmodified	work_listdebug_print_labelblockiinstrexpr	call_namefunc_defcfgro   ksized_loopsvisitedsdeads                      r9   r`   zInlineClosureCallPass.runX   s    ##DLL1
t,,2245	'(?@G%MMOMFE%ejj1 ,5eRYY/ ;;D!$0TWW5F$)-t$L	#()-$4 !!7!7!*E1dIG'+H! !5!5!*E1h@'+H! !5!5!&	8='+H), 0 #%dll&9&9:)$,,*=*=>C01IIKE<AJJLIqAs58==12IKIG{0B'+- $1q!*DLL#wq4<<..<<djjJ  $H$ !$,,/ *$,,*=*=>C( .LL''-. "$,,/"/0C0C"DDLL 	DLL''(E; Js   !M8c           	         t        | j                  j                          t        |dk(  xs |dk(         t        |j                        dvrt        d      t        | j                  |j                  d          d	d}t        | j                  | j                  j                  j                  j                  ||||t               y)
N)reducebuiltins)r   
_functools)      z^invalid reduce call, two arguments are required (optional initial value can also be specified)r   c                 \    t        |      }||}nt        |      }|D ]  } | ||      } |S rL   )iternext)fAvitr   as         r9   reduce_funcz<InlineClosureCallPass._inline_reduction.<locals>.reduce_func   s=    aB}H aGHr;   rz   callee_validatorTrL   )r   rM   	reductionrq   args	TypeErrorcheck_reduce_funcr5   inline_closure_callfunc_idri   __globals__r:   )rQ   rz   r}   r~   r   r   r   s          r9   rj   z'InlineClosureCallPass._inline_reduction   s     	D))3334	33 655	7tyy>' ; < < 	$,,		!5	 	LL$,,..33??1kY0	

 r;   c                    ddl m} |j                  }|j                  }t	        |t
        j                        rw|j                  dk(  rht	        |j                  |      rR|j                  r*|xj                  |j                  j                  z  c_        y|j                  j                  |_        yt        |dk(  xs |dk(         t        || j                  v       | j                  j                  |       t        |j                        dk(  st        d      t        t         | j"                  |j                  d         }t        t	        |t
        j$                        xr |j&                  d	k(         t)        | j"                  j*                  j,                  j.                  |j0                        }t3        |j                        }	d
|	v r#t        | j4                  |	      }
|
st        d      d|	v r#t        | j6                  |	      }
|
st        d       ||d|	      }|j                  |_        t        j                  d||j8                        }|g| j"                  j:                  |j                  <   ||_        y)Nr   )StencilFuncstencilT)r   znumba.stencils.stencil)r   numbarX   z5As a minimum Stencil requires a kernel as an argumentmake_functionneighborhoodzXstencil neighborhood option should be a tuple with constant structure such as ((-w, w),)index_offsetszYstencil index_offsets option should be a tuple with constant structure such as (offset, )constant)numba.stencils.stencilr   targetr2   r1   r   Globalnamekwsr   rO   rs   rq   r   
ValueErrorr   r   r5   rg   rh   r   r   ri   r   codedict_fix_stencil_neighborhood_fix_stencil_index_offsetsr,   _definitions)rQ   r   r   r   r   lhsr   stencil_def	kernel_iroptionsfixedsf	sf_globals                r9   rl   z%InlineClosureCallPass._inline_stencil   s   6ll{{ x+*8>>;7xxHNN...  $>>--	BB 211	3D4445  ''-499~" 8 9 9NDLL$))A,G
;0 2/1	3"4<<#7#7#<#<#H#H#.#3#35	txx.W$$88'BE B  g%$997CE B  J8IIiTXX6	/8k!!#((+r;   c                 @   t        | j                  |d         }t        t        |d             g }|j                  D ]Q  }t        | j                  |      }t        t        |d             |j                  t        |j                               S t        |      |d<   y)z
        Extract the two-level tuple representing the stencil neighborhood
        from the program IR to provide a tuple to StencilFunc.
        r   rb   T)r   r5   r   hasattrrb   rs   tuple)rQ   r   dims_build_tupleres
window_varwin_build_tuples         r9   r   z/InlineClosureCallPass._fix_stencil_neighborhood   s     *$,,8OP('23*00 	5J,T\\:FOGOW56JJu_2234	5 #(*r;   c                     t        | j                  |d         }t        t        |d             t	        |j
                        |d<   y)z
        Extract the tuple representing the stencil index offsets
        from the program IR to provide to StencilFunc.
        r   rb   T)r   r5   r   r   r   rb   )rQ   r   offset_tuples      r9   r   z0InlineClosureCallPass._fix_stencil_index_offsets  s@    
 &dllGO4LMg./#(););#< r;   c           	          t        t        |t        j                        xr |j                  dk(         t        | j                  | j                  j                  j                  j                  ||||t               y)Nr   r   T)r   r1   r   rg   rh   r   r5   r   ri   r   r:   )rQ   rz   r}   r~   r   s        r9   rk   z%InlineClosureCallPass._inline_closure  sa    
8RWW- /.	0DLL LL0055AA!1h)-@	B r;   N)__name__
__module____qualname____doc__rR   r`   rj   rl   r   r   rk   rY   r;   r9   rJ   rJ   L   s4     ;=E IV:0d r;   rJ   c                    t        t        | |      }|t        d      t        |t        j
                  t        j                  f      rZt        |j                  t        j                  j                  j                        st        d      |j                  j                  }n#t        |d      st        |d      st        d      t        |d      r|j                  n|j                  }|j                   dk(  st#        d      |S )zsChecks the function at func_var in func_ir to make sure it's amenable
    for inlining. Returns the function itselfzMReduce function cannot be found for njit                             analysiszInvalid reduction functionr   __code__r   z*Reduction function should take 2 arguments)r   r   r   r1   r   FreeVarr   r2   r   coreregistryCPUDispatcherpy_funcr   r   r   co_argcountr   )r5   func_varr   f_codes       r9   r   r     s     :K & ' 	'+

BII67+++**--;;=9::!''//k6*j1566f- ''  "DEEr;   c                   H    e Zd ZdZdddddeddfdZ	 ddZddZd	dZd Z	y)
InlineWorkera=   A worker class for inlining, this is a more advanced version of
    `inline_closure_call` in that it permits inlining from function type, Numba
    IR and code object. It also, runs the entire untyped compiler pipeline on
    the inlinee to ensure that it is transformed as though it were compiled
    directly.
    Nc	                 @   d }	ddl m}
 ||||f}|D cg c]  }|du }}t        |      r0t        |      s% |	|d        |	|d        |	|d        |	|d       nt        |      r	 |	|d	       |
j                  | _        || _        || _        || _        || _	        || _
        || _        t        d
      | _        ||f}|D cg c]  }|du  }}t        |      rt        |      sd}t        ||z        t        |       | _        || _        || _        yc c}w c c}w )a1  
        Instantiate a new InlineWorker, all arguments are optional though some
        must be supplied together for certain use cases. The methods will refuse
        to run if the object isn't configured in the manner needed. Args are the
        same as those in a numba.core.Compiler.state, except the validator which
        is a function taking Numba IR and validating it for use when inlining
        (this is optional and really to just provide better error messages about
        things which the inliner cannot handle like yield in closure).
        c                 <    | t        dj                  |            y )Nz{} must not be None)r   format)argr   s     r9   checkz$InlineWorker.__init__.<locals>.checkH  s#    { 5 < <T BCC r;   r   )DefaultPassBuilderN	targetctxlocalspipelineflags	typingctxr   zKtypemap and calltypes must both be either None or have a value, got: %s, %s)numba.core.compilerr   anyalldefine_untyped_pipeline_compiler_pipeliner   r   r   r   r   	validatorrc   r{   r   !_permit_update_type_and_call_mapstypemap	calltypes)rQ   r   r   r   r   r   r   r   r   r   r   compiler_argsxcompiler_grouppairpair_is_noner8   s                    r9   rR   zInlineWorker.__init__6  s3   $	D 	; #FHe<1>?A!4-??~s>':)[)&(#(J'%! )[)"4"L"L"" 
",^< #+/0aT	00|S%6(CC$J''585F1F."; @, 1s   DDc                 N	   d } ||      }| j                   | j                  |        ||      }|j                  }	|j                  |   }
|
j                  }|j                  }t        t        j                  j                         t        |j                  j                                     }t        ||dz         }t        |      }||_        t        |j                               }t        |j                               }t        j                  j                  |       | j                  d       t        |       t!        |      }| j                  d|       t#        |      dk(  sJ |d   }i }t%        |j&                  j(                  j+                               D ]  }|j,                  |vst/        |j0                  j2                  |j,                        }|	j5                  ||j6                        }|j5                  ||j6                         |||j,                  <    | j                  d|       t9        ||       | j                  d	       t        |       |j0                  j:                  }t=        |||j                  |   j6                  |      }| j>                  r+|tA        d
      | jC                  ||       |j                  }| j                  d       t        |       tE        ||       g }tG        jH                  |	|j6                        }|j                  |dz   d |_        tK               }||j                  |<   |jM                  ||f       |j                  d| |_        |j                  jM                  tG        jN                  ||
j6                               tQ        |      }tS        ||
jT                  |       |
jT                  j,                  |jV                  v rW||jV                  |
jT                  j,                     v r2|jV                  |
jT                  j,                     jY                  |       |D ]<  }||   }|	|_        t[        ||       ||j                  |<   |jM                  ||f       > | j                  d       t        |       ||||fS )a   Inlines the callee_ir in the caller_ir at statement index i of block
        `block`, callee_freevars are the free variables for the callee_ir. If
        the callee_ir is derived from a function `func` then this is
        `func.__code__.co_freevars`. If `arg_typs` is given and the InlineWorker
        instance was initialized with a typemap and calltypes then they will be
        appropriately updated based on the arg_typs.
        c                     | j                         }i |_        | j                  j                         D ]6  \  }}t        j                  | j                  |         }||j                  |<   8 |S rL   )copyr-   rb   deepcopy)the_irkernel_copyblock_labelr}   	new_blocks        r9   copy_irz'InlineWorker.inline_ir.<locals>.copy_ir{  se     ++-K!#K&,mm&9&9&; <"U MM&--*DE	2;"";/< r;   NrX   After relabelcallee_scopes = r   r+   var_dict = After local var renamez%arg_typs should have a value not NoneAfter arguments rename: After merge in).r   scoperf   r2   r-   maxr	   _the_max_labelr   rp   r   r   minupdater{   rn   _get_all_scopesrq   r   	localvars_conr.   r   rH   r   unique_nameredefiner,   r   ri   _get_callee_argsr   r   update_type_and_call_maps_replace_args_withr   Blockr   rs   Jumpr   _replace_returnsr   r   remove_add_definitions)rQ   	caller_irr}   r~   	callee_ircallee_freevarsarg_typsr   callee_ir_originalr   r   	call_exprcallee_blocks	max_label	min_labelcallee_scopescallee_scopevar_dictvarrF   new_varcallee_funcr   
new_blocksr   	new_label
topo_orderlabels                               r9   	inline_irzInlineWorker.inline_irp  s   	 I&	 >>%NN9% %Y/

1KK	!(( ##((*	  %%'(
	 -]IMJ$]3(	**,-	**,-	&&y1)I (6+];M"a'('$Q'//44;;=> 	-CHH/8%%11388 =  ..377.C
 %%l%@%,"	- 	1]H-12I  '',,	;

18I8I )+ 11 GHH**9h?%,,M34I=$/
HHUEII.	AEF+	L	&/	#9i01ZZ^


"'')UYY78 %]3
i@ LL!7!77!7!78I8I!JJ""5<<#4#45<<YG   	.E!%(EEKY.&+IU#uen-	. 	)*I!=(JFFr;   c                 ~    | j                  |      }|j                  j                  }| j                  ||||||      S )a   Inlines the function in the caller_ir at statement index i of block
        `block`. If `arg_typs` is given and the InlineWorker instance was
        initialized with a typemap and calltypes then they will be appropriately
        updated based on the arg_typs.
        )r  )run_untyped_passesr   co_freevarsr"  )rQ   r  r}   r~   functionr  r  freevarss           r9   inline_functionzInlineWorker.inline_function  sH     ++H5	$$00~~i9h'/  1 	1r;   c                    ddl m}m} ddlm} ddlm} ddlm}  |       }d|_	        | j                  |_
        | j                  |_        | j                  |_        | j                  |_        | j                  |_        ||j                  _        |j                   j#                  |      |_        d|_        d|_        d|_         |d      |_        d|_         |       |_        i |_         |       j5                  |       t7        |j8                  j$                  j:                  j<                        t>        j@                  fz  |_!        | jE                  |      }	|	jG                          |	jI                  |       |j                  S )a&  
        Run the compiler frontend's untyped passes over the given Python
        function, and return the function's canonical Numba IR.

        Disable SSA transformation by default, since the call site won't be in
        SSA form and self.inline_ir depends on this being the case.
        r   )	StateDict_CompileStatus)ExtractByteCode)bytecode)ParforDiagnosticsNF)%r   r*  r+  numba.core.untyped_passesr,  
numba.corer-  numba.parfors.parforr.  r5   r   r   r   r   r   
enable_ssaFunctionIdentityfrom_functionr   r   r   type_annotationstatusreturn_typeparfor_diagnosticsmetadatarun_passrq   bcpysig
parametersr   pyobjectr   r   finalizer`   )
rQ   ri   r2  r*  r+  r,  r-  r.  statepms
             r9   r$  zInlineWorker.run_untyped_passes  s%    	B=':....{{jj!+ 11??E $%e, #4#6 ""5) ))//::;u~~>OO
$$U+

u}}r;   c                 6   ddl m} ddlm} | j                  sd}t        |      ddlm} t        j                  |j                        |_        t        j                  j                  j                  ||        ||      }t        j                  |j                        |_        |j!                  | j"                  | j$                  ||d      \  }}}	}
 |       j'                  |      }t        j                  |j                        |_        t)        |||	| j"                         |D cg c]  }|j+                  d      s| }}|D ]  }|j-                  |        | j.                  j1                  |       | j2                  j1                  |	       yc c}w )z_ Updates the type and call maps based on calling callee_ir with
        arguments from arg_typsr   )reconstruct_ssa)PreLowerStripPhisz_InlineWorker instance not configured correctly, typemap or calltypes missing in initialization.typed_passesNarg.)numba.core.ssarC  numba.core.typed_passesrD  r   r   r0  rF  r	   build_definitionsr-   r   r   r   analysisdead_branch_prunetype_inference_stager   r   _strip_phi_nodesr   
startswithrd   r   r  r   )rQ   r  r  rC  rD  r8   rF  	f_typemap_f_return_typef_calltypesr?   vname	arg_namesr   s                 r9   r  z&InlineWorker.update_type_and_call_maps   sY    	3=55:CS/!+!)!;!;I<L<L!M	

--iB#I.	!)!;!;I<L<L!M	 (<<NNDNNIx
			a &'88C	!)!;!;I<L<L!M		9 +T^^	= )2NuU5E5Ef5MUN	N 	AMM!	I&k*	 Os   *FFrL   )F)
r   r   r   r   r:   rR   r"  r(  r$  r  rY   r;   r9   r   r   .  sD      .8#v  yGv	1(T+r;   r   c                 F  . |j                   }|j                  |   }|j                  }t        d      } |d|d|       t	        |d      r|j
                  n|j                  }t	        |d      r|j                  n|j                  }t        |t        j                        rddlm} |j                  |d	      }nt        ||      }| ||       |j                   }t#        t$        j&                  j)                         t#        | j                   j+                                     }t-        ||dz         }t/        |      }||_        t1        |j+                               }t#        |j+                               }t$        j&                  j3                  |        |d       t5        |       t7        |      } |d|       t9        |      dk(  sJ |d   }i }|j:                  j<                  j?                         D ]q  }|j@                  |jB                  vstE        |jF                  jH                  |j@                        }|jK                  ||jL                        }|||j@                  <   s  |d|       tO        ||        |d       t5        |       tQ        |||j                  |   jL                  |       } |d       t5        |       |r|r| jS                  |      } |d|       t        |tT              rZtV        jX                  jZ                  .tV        j\                  ._/        tV        j\                  f._0        tU        .fd|D              } n7t        |tb        jd                        r|jf                  dk(  sJ |jh                  } t9        |jB                        t9        |       k(  sJ tk        ||         |d       t5        |       |rddlm6}! t%        jn                  |j                         |_8        tr        jt                  jv                  jy                  ||       	 |!j{                  ||||d
      \  }"}#}$}%t        ||"|$|       |"D &cg c]  }&|&j                  d      s|& }'}&|'D ]  }(|"j                  |(        |j3                  |"       |	j3                  |$       t        ||       g })tc        j                  ||jL                        }*|j                  |dz   d
 |*_        t               }+|*| j                   |+<   |)j                  |+|*f       |j                  d
| |_        |j                  j                  tc        j                  ||jL                               t        |      },t        ||j                  |+       |j                  j@                  | jp                  v rW|| jp                  |j                  j@                     v r2| jp                  |j                  j@                     j                  |       |,D ]<  }-||-   }||_         t        | |       || j                   |-<   |)j                  |-|f       >  |d       t5        |        |
|)D ]  }|
j                  |        ||fS # t|        $ r |!j{                  ||||d
      \  }"}#}$}%Y Zw xY wc c}&w )a  Inline the body of `callee` at its callsite (`i`-th instruction of
    `block`)

    `func_ir` is the func_ir object of the caller function and `glbls` is its
    global variable environment (func_ir.func_id.func.__globals__).
    `block` is the IR block of the callsite and `i` is the index of the
    callsite's node. `callee` is either the called function or a
    make_function node. `typingctx`, `typemap` and `calltypes` are typing
    data structures of the caller, available if we are in a typed pass.
    `arg_typs` includes the types of the arguments at the callsite.
    `callee_validator` is an optional callable which can be used to validate the
    IR of the callee to ensure that it contains IR supported for inlining, it
    takes one argument, the func_ir of the callee

    Returns IR blocks of the callee and the variable renaming dictionary used
    for them to facilitate further processing of new blocks.
    r   zFound closure call: z with callee = r   closurer   )compilerT)inline_closuresNrX   r   r   r+   r   r   r   zcallee's closure = c              3   .   K   | ]  } |        y wrL   rY   ).0r   cellgets     r9   	<genexpr>z&inline_closure_call.<locals>.<genexpr>  s     6'!*6s   build_tuplezAfter closure renamerE  rG  r   )Lr   rf   r2   rc   r   r   r   rV  __closure__r1   pytypesFunctionTyper0  rW  run_frontendr   r-   r   r	   r   r   rp   r   r   r   r  rn   r  rq   r  r  r.   r   r%  rH   r   r  r  r,   r   r  r   r   ctypes	pythonapi
PyCell_Get	py_objectrestypeargtypesr   rg   rh   rb   _replace_freevarsrF  rJ  r   r   r   rK  rL  rM  	Exceptionr   rO  rd   r	  r
  r   rs   r  r   r  r   r  r  )/r5   glblsr}   r~   calleer   r   r  r   r   rz   r   replace_freevarsr   r   r  r{   callee_codecallee_closurerW  r  r  r  r  r  r  r  r  rF   r  r   rV  rb   rF  rP  f_return_typerR  r?   rS  rT  r   r  r   r  r   r!  r[  s/                                                 @r9   r   r   B  s   * KKEJJqMEI#$9:K&/@&I!(!8&++fooK 3 nn9?9K9K  &'../'))&$)G	"5+6	 ##$$M H++002C8K8K8M4NOI(	AFM /M$IM&&()IM&&()I""9- 	 $M2M"M2!#$# #LH%%**113 )K3334!!--sxx9Lnn\swwn?G!(HSXX) x()()	 Ivuzz!}/@/@'JD*+	 *((8)73gu%&&11G$..GO & 0 02G6g66Ew0

m35 4MMEK++,E
:;:-/*+I+!)!;!;I<L<L!M	

--iB	A+@@9i4 AY! 	 	9 +Y	8 )2NuU5E5Ef5MUN	N 	AMM!	y!%}d+J		*IZZA'INI )GNN9y),-BQEJ	JJbggi34 !/J]ELL)< 	W111W11%,,2C2CDDU\\../66yA  *e$%( %u5%.)*  ! 	$EU#	$(""a  	A+@@9i4 AY!	A Os   &Y4 Z)Z4#ZZc                    | j                   dk(  rCt        | j                        }| j                  rd}t	        j
                  || j                        | j                   dk(  r| j                  g}nJt        j                  |       r| j                         }n$t        dj                  | j                               t        d      }t        |t        j                         rt"        j$                  j&                  j)                  |      }d }fd}	d }
| j                   dk(  rt+        | j,                        }ni }t"        j$                  j.                  j1                  |||||	|
      S t3        |d	      r|j4                  n|j6                  }|r, |d
|       t        |t8              rbg }|D ]T  }t        |t:        j<                        r|j?                  |       /|j?                  t;        j@                  |             V ||z   }|S t        |t:        j<                        st        |tB              rm|jE                  |      }t        |t:        jF                        sJ |j                   dk(  sJ |jH                  D cg c]  }|jE                  |       }}||z   }|S tK        dj                  |            |S c c}w )zGet arguments for calling 'callee', including the default arguments.
    keyword arguments are currently only handled when 'callee' is a function.
    rU   z,Calling a closure with *args is unsupported.getattrzUnsupported ir.Expr.{}z$inline_closure_call default handlingc                     |S rL   rY   indexparamdefaults      r9   r[   z"_get_callee_args.<locals>.<lambda>  s    w r;   c                 0    t        j                  |      S rL   )r   Const)rt  ru  rv  r,   s      r9   r[   z"_get_callee_args.<locals>.<lambda>  s    #8N r;   c                 8    t        dj                  | |            )Nz.Stararg not supported in inliner for arg {} {})NotImplementedErrorr   rs  s      r9   stararg_handlerz)_get_callee_args.<locals>.stararg_handler  s"    %@GG5"# #r;   defaultszdefaults = r2   r,   r]  z)Unsupported defaults to make_function: {})&rh   ra   r   varargr   r4   r,   r2   r	   is_operator_or_getitem	list_varsr   r   rc   r1   r_  r`  r   r   utilspysignaturer   r   r   fold_argumentsr   r|  __defaults__r   r   Varrs   rx  strr   rg   rb   rz  )r  rk  r,   r5   r   r8   r{   r<  normal_handlerdefault_handlerr{  r   callee_defaultsdefaults_listr   default_tuple
const_valss     `              r9   r  r    sy    ||vINN#@C))#y}}==		" 		(	(	3""$077	EFF#$JKK &'../

  ,,V4>N	# <<6!y}}%CCzz  //4no 	 /6fj.I6?? & 3 3 	7/51 "( IA!!RVV,%,,Q/ &,,RXXA3-GHI m+  _bff5!/37 ' 6 6 G"="'':;:%((M9:9#0#6#68 &44Q7 8
 8j(
  *?FF')* * 8s   J>c                       fd}|S )Nc                  v    t         j                  r(t        dz   dj                  d | D              z          y y )Nz:  c              3   2   K   | ]  }t        |        y wrL   )r  )rZ  r   s     r9   r\  z9_make_debug_print.<locals>.debug_print.<locals>.<genexpr>)  s     )?Q#a&)?s   )r   DEBUG_INLINE_CLOSUREprintjoin)r   prefixs    r9   r{   z&_make_debug_print.<locals>.debug_print'  s1    &&&4-"'')?$)?"??@ 'r;   rY   )r  r{   s   ` r9   rc   rc   &  s    A r;   c                 F    t         j                  r| j                          y y rL   )r   r  dump)r5   s    r9   rn   rn   -  s    "" #r;   c                     g }| j                         D ]/  \  }}|j                  |vs|j                  |j                         1 |S )z+Get all block-local scopes from an IR.
    )rb   r   rs   )r-   
all_scopesr!  r}   s       r9   r  r  2  sH     J +uz)ekk*+ r;   c                 *   | j                         D ]  \  }}|j                  t        j                        }|D ]W  }t	        |j
                  t        j                        s(|j
                  j                  }|t        |      k  sJ ||   |_        Y  y)z@
    Replace ir.Arg(...) with real arguments from call site
    N)	rb   r/   r   r0   r1   r2   Argrt  rq   r-   r   r!  r}   assignsr7   idxs          r9   r	  r	  <  s|      'u""299- 	'D$**bff-jj&&c$i(!#Y
		''r;   c                    | j                         D ]  \  }}|j                  t        j                        }|D ]  }t	        |j
                  t        j                        s(|j
                  j                  }|t        |      k  sJ t	        ||   t        j                        r||   |_        vt        j                  ||   |j                        |_          y)zJ
    Replace ir.FreeVar(...) with real variables from parent function
    N)rb   r/   r   r0   r1   r2   r   rt  rq   r  rx  r,   r  s          r9   rh  rh  I  s      	?u""299- 	?D$**bjj1jj&&c$i(d3i0!%cDJ!#$s)TXX!>DJ	?	?r;   c                 t   | j                         D ]  \  }}g }t        t        |j                              D ]z  }|j                  |   }t	        |t
        j                        r|dz   t        |j                        k(  sJ t        j                  |j                  ||j                        |j                  |<   |j                  j                  t        j                  ||j                               |D ]K  }|j                  j                  |j                  j                  k(  s1|j                  j                  |_        M t	        |t
        j                        s)t	        |j                  t
        j                        sO|j                  j                  dk(  sj|j                  |       }  y)zN
    Return return statement by assigning directly to target, and a jump.
    rX   castN)rb   rangerq   rf   r1   r   Returnr0   r2   r,   rs   r  r   r   rg   rh   )	r-   r   return_labelr!  r}   castsr~   r7   r  s	            r9   r  r  Y  s.     #us5::' 	#A::a=D$		*AUZZ010 "		$**fdhh G

1

!!"'',"AB! 6D{{''4::??:%)ZZ%5%5
6 T299-tzz2773JJMMV+T"	##r;   c                     | j                   }|j                  t        j                        }|D ]4  }||j                  j
                     j                  |j                         6 y)zF
    Add variable definitions found in a block to parent func_ir.
    N)r   r/   r   r0   r   r   rs   r2   )r5   r}   definitionsr  r7   s        r9   r  r  o  sS     &&Kryy)G 9DKK$$%,,TZZ89r;   c                    d}d}d}d}|t        |j                        k  r|j                  |   }t        |t        j                        r#|r|r|j
                  |j                  k(  rd}n;nt        |t        j                        r||j                  }|j
                  }t        t        | |      dk(  rt        |j                  d   t        j                        r|j                  d   }|}|}	t        |j                        }
nt        |t        j                        rit        |j
                  t        j                        rE|sC|j
                  }|j                  }t!        | |      }t#        t        t$        | |             |}	i }
nn|dz   }|t        |j                        k  rt#        |xr |        t'        d      |j                  	          ||	
fS )zLook for statement like "x = numpy.array(y)" or "x[..] = y"
    immediately after the closure call that creates list y (the i-th
    statement in block).  Return the statement index if found, or
    raise GuardException.
    NFr   T)arraynumpyrX   find_array_call)rq   rf   r1   r   Delr2   r   r0   r   r   r   r   r  r   r   SetItemr   r   _find_unsafe_empty_inferredrc   )r5   r}   	array_varlist_var_dead_after_array_calllist_varr~   r   r   r   array_stmt_index	array_kws	array_defs               r9   _find_arraycallr  y  s    I%*"H	A
c%**o


1eRVV$I%++*F15.ryy),,C;;DmWd37IItyy|RVV499Q<	#$  N	

+bff-{{HI&w	:IE5w	JK I E? c%**o
B I889('(4D)EF%y00r;   c                 &   t        d      }t        | |      } |d|d|       t        t        |t        j
                        xr |j                  dk(         |j                  }t        | |      } |d|d|       t        t        |t        j
                        xr |j                  dk(         |j                  }t        | |      } |d|d	|       t        t        |t        j                        xrF |j                  t        k(  xs1 |j                  t        j                  j                  j                  k(         t        |j                         }	d
|j                  j"                  g}
|	dk(  rF|
||j                  j$                  <   t        | |j                   d   d      }d|j                   d   |fS |	dk(  rT|
||j                  j$                  <   t        | |j                   d   d      }t        | |j                   d   d      }|||fS t&        )zzFind the iterator's actual range if it is either range(n), or
    range(m, n), otherwise return raise GuardException.
    find_iter_rangezrange_iter_var =  def = getiterzrange_var = z range_def = rU   zfunc_var = z func_def = )z"array comprehension"z
closure ofrX   r   Tlhs_onlyr   )rc   r   r   r1   r   rg   rh   r2   ri   r   r  r   miscspecialprangerq   r   r,   r   r   )r5   range_iter_varrN   r{   range_iter_def	range_var	range_defr   r   nargsswappingstopstarts                r9   _find_iter_ranger    s    $$56K#G^<N#^YOJ~rww/ +*,$$Iw	2I	?IFJy"''*Ey||v/EF~~Hgx0HxBJx+ :^^u$ 9^^uzz11888; 	E79K9KLHz'/	##$gy~~a'84H9>>!$h//	!'/	##$w	q(9DIgy~~a'84HtX&&r;   c                 l   t        |t        j                        r|j                  fd}t	        |      |fS t        |t        j
                        rd }t	        t        j                  |      |fS t        |t        j                        rd }t	        t        j                  |      |fS t        |t        j                        rd }t	        t        j                  |      |fS t        |t        j                        rd }t	        t        j                  |      |fS d}t        j                  |      )z
    An implementation of len(iter) for internal use.
    Primary use is for array comprehensions (see inline_closurecall).
    c                     |\  }t            d   } t        j                  |      | ||      }|j                  j                  }t        | |||j                  |j                              S rW   )r&   r
   create_struct_proxycounttyper!   load)	contextbuildersigr   r2   	iter_typeiterobjint_typeval_types	           r9   codegenz#length_of_iterator.<locals>.codegen  sl    HU&x03I<g11)<Wg=BDG}}))H%gw&-ll7==&AC Cr;   c                     |\  }| j                  t        j                        }t        | ||j                  d   |      }t        | |||j                        S )Nr   )get_value_typer   intpr%   r   r!   size)r  r  r  r   r2   intp_tr  s          r9   r  z#length_of_iterator.<locals>.codegen  sJ    HU++EJJ7F&w!eLG%gwMMr;   c                 B   |j                   \  }|\  }| j                  t        j                        }| j	                  |||      }|j
                  } t        |      | ||j                        }	t        j                  ||	j                        }
t        | |||
d         S )N)r2   r   )r   r  r   r  make_helper
array_typer'   r  r
   unpack_tupleshaper!   )r  r  r  r   itertyr2   r  r  arraytyaryr  s              r9   r  z#length_of_iterator.<locals>.codegen  s    IVHU++EJJ7F))'6)GG''G%*W%gwgmmLC((#))<E%gwaIIr;   c                     |j                   \  }|j                  }| j                  t        j                        } ||j
                        }t        | |||      S rL   )r   	containerr  r   r  r  r!   )r  r  r  r   r  tupletyr  count_consts           r9   r  z#length_of_iterator.<locals>.codegen  sK    IV&&G++EJJ7F /K%gwLLr;   c                     |\  }| j                  t        j                        }ddlm}  || ||j
                  d   |      }t        | |||j                        S )Nr   r$   )r  r   r  numba.typed.listobjectr%   r   r!   r  )r  r  r  r   r2   r  r%   r  s           r9   r  z#length_of_iterator.<locals>.codegen  sM    HU++EJJ7F?&w!eLG%gwMMr;   zdUnsupported iterator found in array comprehension, try preallocating the array and filling manually.)r1   r   RangeIteratorType
yield_typer#   ListIterr  ArrayIteratorUniTupleIterListTypeIteratorTyper   TypingError)r   valr  r8   r  s       @r9   length_of_iteratorr    s    #u../>>	C 3'00	C	(	N
 S)722	C,,	-		J S)722	C++	,	M S)722	C33	4	N S)722?  %%r;   c                    t        d      }t        t        |j                        dk(         t	        t        |j                              }t        | | j                  |         \  }	}
}d}d}d|v rt        t        |d   t        j                               t        | |d         }t        t        |t        j                        xr |j                  dk(         t        | |j                        }t        | |	      } |d|	d|       t        |t        j                        r%|j                  dk(  rt        | |j                        }t        t        |t        j                        xr |j                  d	k(         t        t        |j                        d
k(         g }|j                   D ]8  }|j#                  |      D cg c]  }|j$                  |v  }}t'        |      s:| j                  |   } |d|       |j)                  t        j*                        D ]  }|j                  }t        |t        j                        s*|j                  dk(  s:t        | |j,                        }t        |t        j                        sk|j                  dk(  s{|j.                  dk(  st        | |j                        } |d|||u        ||u s|j1                  |||f        ; t        t        |      dk(         |d
   \  }}}t3        d |j5                  |j$                        D              } |d||j6                  t3        |g      z         t        ||j6                  t3        |g      z  k(         g }g }| j                  |j$                     }|j)                  t        j*                        D ]  }|j                  }t        |t        j                        s*|j                  dk(  r;t        | |j                        } |d|       |j1                  |j                         t|j                  dk(  s|j1                  |j8                          t        t        |      dk(  xr t        |      dk(         |d
   } |d
   }!t        t        |j6                        dk(         | j                  t	        t        |j6                                 }"|"j:                  }#|"j<                  }$|"j>                  }%g }&g }'d }(tA        t        |"j                         dz
        D ]y  })|"j                   |)   }t        |t        j*                        r=|j                  u s |(|j                  |'      r|'j1                  |j8                         i|&j1                  |       {  |d|'       tC        tD        | | |      }*|$jG                  d|%      }+|*r|*d
   d
k(  r|!}+n2|&j1                  tI        | |+t        jJ                  d|%      |%             |$jG                  d|%      },|*rn|*\  }-}.}/|-d
k(  r|.}0n1t        j                  jM                  tN        jP                  |.|-|%      }0|rt        |/t        jR                        rd|/_*        tV        |/_        nv|rn|$jG                  d|%      }1|&j1                  tI        | |1t        jR                  dtX        |%      |%             t        j                  j[                  |1| fd|%      }0nt\        |&j1                  tI        | |,|0|%             |$jG                  d |%      }2|&j1                  tI        | |2t        j                  j_                  |,g|%!      |%             |$jG                  d"|%      }3|$jG                  d#|%      }4|r|r|$jG                  d$|%      }5|$jG                  d|%      }6|&j1                  tI        | |5||%             |&j1                  tI        | |6t        j                  ja                  |5|j.                  |%      |%             |&j1                  tI        | |4t        jR                  d%tb        jd                  |%      |%             d|6fg}nB|r:|&j1                  tI        | |4t        jR                  d&tf        |%      |%             g }nt\        |&j1                  tI        | |3t        j                  j[                  |4|2fti        |      |%      |%             |'D ]  }7|&j1                  tI        | |7|3|%             ! |&j1                  |#       |&|"_        |*r|*d
   d
k7  r|j:                  }#t        |#t        jj                        sJ |#jl                  }8| j                  |8   }9|9j>                  }%|9j                   jo                  d
tI        | |+t        j                  jM                  tN        jP                  |!|*d
   |%      |%             n|j>                  }%|j:                  }#|j                   d
d }&|$jG                  d'|%      }:|$jG                  d(|%      };|&j1                  tI        | |;t        jJ                  d|%      |%             |&j1                  tI        | |:t        j                  jM                  tN        jp                  |+|;|%      |%             |&j1                  tI        | |+|:|%             |&j1                  |#       |&|_        tA        t        |j                               D ]c  })|j                   |)   |u s |d)       t        jr                  |3|+|j                  jt                  d
   |j>                  *      |j                   |)<   e | j                  |   j                   |
   }t        |t        j*                        rYt        |j                  t        j                        r5|3|_        |j                  g| jv                  |j8                  jT                  <   y+c c}w ),a  Look for array(list) call in the exit block of a given loop, and turn
    list operations into array operations in the loop if the following
    conditions are met:
      1. The exit block contains an array call on the list;
      2. The list variable is no longer live after array call;
      3. The list is created in the loop entry block;
      4. The loop is created from an range iterator whose length is known prior
         to the loop;
      5. There is only one list_append operation on the list variable in the
         loop body;
      6. The block that contains list_append dominates the loop head, which
         ensures list length is the same as loop length;
    If any condition check fails, no modification will be made to the incoming
    IR.
    inline_arraycallrX   Ndtyperq  zlist_var = r  r  
build_listr   zcheck loop body block rU   rs   zlist_def = c              3   &   K   | ]	  \  }}|  y wrL   rY   )rZ  lbs      r9   r\  z$_inline_arraycall.<locals>.<genexpr>X  s     <da<s   zpreds = iternextziter_def = 
pair_firstc                 |    t        | t        j                        r"|D ]  }|j                  | j                  k(  s y y)NTF)r1   r   r  r   )r  removedr   s      r9   
is_removedz%_inline_arraycall.<locals>.is_removed|  s7    c266"  66SXX%  r;   zremoved variables: rt  r}  r  )fnr   rhsr,   r   len_funcr  r+   rY   
size_tuplerb   r,   r  
empty_func	dtype_modemptyunsafe_empty_inferred
next_indexonezReplace append with SetItem)r   rt  r2   r,   T)<rc   r   rq   exitsr   r   r  r-   r1   r   r  r   rg   rh   r2   rb   rf   in_loopsheaderr   r/   r0   ri   attrrs   setpredecessorsentriesr   
terminatorr   r,   r  r   r  r  _new_definitionrx  binopoperatorsubr   r   r   r  rU   r   r]  rq  npr  r  ra   Branchtruebrinsertaddr  r   r   )<r5   r   r   looprN   enable_prangerP   r{   
exit_blockr  array_call_indexr  	dtype_defdtype_mod_deflist_var_deflist_append_stmtsr!  r  in_visited_loopsr}   r7   r   r   list_defappend_block_labelappend_blockappend_stmtpreds	iter_varsiter_first_varsloop_headeriter_defiter_variter_first_var
loop_entryr  r   r,   stmtsr  r  r~   r  	index_varsize_varr  r  range_func_defsize_vallen_func_varsize_tuple_varr  r  dtype_mod_var	dtype_varr  block_idr6   next_index_varr  s<                                                               r9   rt   rt     s>
   " $$67KC

Oq !d4::&'J,;
+-)H	
 IM)
9W-rvv67 #7Ig,>?	
9bgg.L9<<93LM&w	@!'84LxLA,(\__-F%g|/A/ABJ|RWW- ,OO|+- C""#q()  G :=e9LMAAHH/MM#$u%,e4$$RYY/ 	GD::D$(TWW->)'499=x1hkkY6N$MMX5-gx~~FHx (L 8:</)00%1EF	GG. C!"a'(4Ea4H1k <c..t{{;<<E
EDLL38J7K3L$LNEdllS*<)=%>>?@ IO..-K&&ryy1 4zzdBGG$ww*$)'4::>M84  ,L(&&t{{34 C	Na=C$8A$=>|H$Q'N
 C"#T$,,%7 89J&&JE
..CEG 3z'!+, q!tRYY'x':djj'+JNN4;;'LL %w/ &7CIw,IYq\Q&"	 	_Wi%'XXBC%@#G 	H ~~fc*H&/#t^A:Hww}}$E), % .H Z		B"3N#2N   >>*c:LLL,)+3G3E7:*< *-	. /
 ww||L8+rs|KH  	LL(HcBC^^L#6N	LL.$$H:3$?F G w,Ic2J]{C8NN7C0	_]M38 	9_YGGOOM9>>3?F 	G 	_Z7BHH#!FM 	Ny)*	 LL		13H!#	 
 I   
LL)j>*;T)_"%  '(+- .
  D_Wc9cBCD 
LLJOQ<1 %//Jz299565!((H..*C''CHHOOYGGMMX\\~&/l " =	 oo ++
  2&c:nnUC(_WcXXA#.5 	6 	_WnWW]]hll	s'* # ,-02 	3 	_WiMNZ   3|(()* FQ;.56#%:: 	!'',,Q/[__$FLa F >>*%**+;<D$		"z$**bgg'F
26**T[[--.A Ns   ?o*c                 H   t          t        t        |t        j                        xr |j
                  dk(         |j                  }t        | |      }t        t        |t        j                                t        d      |j                         |j                  t         k(  S )NrU   r  )r  r   r1   r   rg   rh   ri   r   r   rc   r2   )r5   r   rk  
callee_defs       r9   r  r     sw    JtRWW%;$''V*;<YYF0JJz299-.434Z5E5EF444r;   c                    	
  j                   t              }t              t        j	                         D cg c]  }|t               f c}      }t        |j                  |      
 fd 
fd		 fd}t         j                         D ]J  } j                   |   }|j                  D ]*  }t        ||      s|j                  j                  |       , L yc c}w )zLook for assignment like: a[..] = b, where both a and b are numpy arrays,
    and try to eliminate array b by expanding a with an extra dimension.
    c                     t        |       } t        d      | |       t        |t        j                        r4t        t        |      r|S |j                  dk(  r |j                        S t        )zFind numpy array definition such as
            arr = numba.unsafe.ndarray.empty_inferred(...).
        If it is arr = b[...], find array definition of b recursively.
        find_array_defgetitem)
r   rc   r1   r   rg   r   r  rh   r2   r   )arrarr_defr>  r5   s     r9   r>  z)_fix_nested_array.<locals>.find_array_def4  se    
 !#.+*+C9grww'0'7Cy(%gmm44r;   c           	      (   t        d      }j                         D ]  \  }}|j                  }|j                  }t	               }t        t        |            D ]  }||   }	t        |	t        j                        s$|j                  |	j                  j                         |	j                  | u sXg }
|D ]J  }|j                  |v s,|j                  |   v r@|j                  j                  |   vr% ||j                  d       |
j                  |       c ||j                  d       t!        |j                        }t        |t        j"                        r|j$                  }|j'                  d|      }t        j"                  |j                  |      }t)        |||      }g }|j+                  |d|        |j                  |       |j+                  ||d        ||_        |
j                  |       Gt,         |
c c S   t,        )zDouble check if all variables in varlist are defined before
        expr is used. Try to move constant definition when the check fails.
        Bails out by raising GuardException if it can't be moved.
        fix_dependenciesz already definedz not yet definedr  N)rc   rb   r   rf   r  r  rq   r1   r   r0   r  r   r   r2   defmaprs   r   rx  r,   r  r  extendr   )r   varlistr{   r!  r}   r   rf   definedr~   instnew_varlistr  var_defr,   r  	new_const
new_vardefnew_bodyr-   r5   livemapusedefss                     r9   rC  z+_fix_nested_array.<locals>.fix_dependenciesB  s   
 ((:;"LLN #	+LE5KKE::DeG3t9% +AwdBII.KK 0 01zzT)&(#* 9C !$G 3!$WU^!;&)hh'..2G&G +CHH6H I + 2 23 7 +CHH6H I*8#((*K#-grxx#@*-''C.3nnY.LG020LI1@(/)S2JJ/1H$,OOD!H$=$,OOJ$?$,OODH$=19EJ$/$6$6w$?*8$8192  +*?+	#	+J r;   c                 (   t        t        | t        j                               t        t        | j                  t        j
                               t        d      } |d|        | j                  } 	|      } |d|       t        | j                        } |d|       t        t        |t        j                               |j                  dk(  r9t        |j                        }t        t        |t        j                               t        t        |             t        |j                  d         }t        t        |t        j                        xr |j                  dk(          |d|       |j                  D cg c]  }t        |d	
       }} |d|       t        |j                  d         }t        t        |t        j                        xr |j                  dk(          |d|        
||      }|xj                  |z  c_        d|_
        t        j                  |_        t        |d	
      |_        | j"                  |_        |j$                  d= |j$                  d= |j$                  d= |j$                  d= y	c c}w )a  For assignment like lhs[idx] = rhs, where both lhs and rhs are
        arrays, do the following:
        1. find the definition of rhs, which has to be a call to
           numba.unsafe.ndarray.empty_inferred
        2. find the source array creation for lhs, insert an extra dimension of
           size of b.
        3. replace the definition of
           rhs = numba.unsafe.ndarray.empty_inferred(...) with rhs = lhs[idx]
        fix_array_assignzfound SetItem: zfound lhs_def: zfound rhs_def: r  r   r]  z
dim_def = Tr  zextra_dims = zsize_tuple_def = r?  ri   r   r~  r   )r   r1   r   r  r2   r  rc   r   r   rg   rh   r  r   rb   r  r?  r  rt  _kws)r7   r{   r   lhs_defrhs_defdim_defr   
extra_dimssize_tuple_defr>  rC  r5   s            r9   rQ  z+_fix_nested_array.<locals>.fix_array_assigno  s    	
4,-
4::rvv./'(:;%t,kk %%w/ $**5%w/
7BGG,-::$Wgmm<GJw01+GW=> ',,q/:
7BGG,L}1LML'*&}}/ %Wa$? /
 /OZ0'aA
>2773 3!!]2	4'8%njA

*
%%
&wdC

LL LL LL"LL)/s   JN)r-   r   r   r   rp   r  r    rD  r   rf   r   r  )r5   r   r!  empty_deadmaprQ  r}   r7   r-   r>  rC  rN  rO  s   `      @@@@@r9   rv   rv   *  s     ^^F
!&
)Cv&GfkkmDU5#%.DEM$S&'..-PG+Z1f !0 (u%JJ 	(D%t,

!!$'	((c Es    C*c                 f    |g| j                   |j                  <   t        j                  |||      S )N)r2   r   r,   )r   r   r   r0   )r5   r  r2   r,   s       r9   r  r    s+    &+WG"995#66r;   zafter-inferencec                   .     e Zd ZdZ fdZd Zd Z xZS )RewriteArrayOfConstszThe RewriteArrayOfConsts class is responsible for finding
    1D array creations from a constant list, and rewriting it into
    direct initialization of array elements without creating the list.
    c                 N    |j                   | _         t        t        |   |i | y rL   )r   superr[  rR   )rQ   r@  r   r   	__class__s       r9   rR   zRewriteArrayOfConsts.__init__  s#    "D2D@C@r;   c                     t        |      dk(  ry|| _        t        t        ||| j                  ||      | _        | j
                  d uS )Nr   F)rq   
crnt_blockr   _inline_const_arraycallr   rM  )rQ   r5   r}   r   r   s        r9   matchzRewriteArrayOfConsts.match  sF    y>Q5ug"nngyB}}D((r;   c                 P    | j                   | j                  _        | j                  S rL   )rM  r`  rf   rQ   s    r9   applyzRewriteArrayOfConsts.apply  s    #}}r;   )r   r   r   r   rR   rb  re  __classcell__)r^  s   @r9   r[  r[    s    A)r;   r[  c           	         t        d      | j                  fd} G d dt              } |       }| j                  D ]b  }t	        |t
        j                        rt	        |j                  t
        j                        rn|j                  j                  |j                  v r|j                  j                  |j                  j                         |j                  j                  |       t	        |j                  t
        j                        rO|j                  }	|	j                  dk(  rr|j!                          |	j"                  D 
cg c]  }
|
j                   c}
|_        |j                  j                  g|_
        |j                  j                  |       c|	j                  dk(  r|	v rt'        ||j                  |	|j                  |j                  |j(                        rtd|_        t	        |t
        j,                        rP|j                  }||j$                  v r|j(                  j                  |       ||j                  v r
|j.                  j                  |       |j                  j1                  |       |j                  j                  |       |j                  g k(  rg }|j                  D ]  }t	        |t
        j                        r"|j                  j                  |j.                  v s2t	        |t
        j,                        r|j                  |j.                  v rr|j                  |        ||_        g |_        d|_        %|j                  j                  |       |j3                  |      sS|j!                          e |j*                  r|j                  S dS c c}
w )	a|  Look for array(list) call where list is a constant list created by
    build_list, and turn them into direct array creation and initialization, if
    the following conditions are met:
      1. The build_list call immediate precedes the array call;
      2. The list variable is no longer live after array call;
    If any condition check fails, no modification will be made.
    inline_const_arraycallc                 "	   t        t        "|      }t        |xr |d   dk(  xr |d   dk(         t        |j                  d   j                  |v        |   j
                  }t        t        |t        j                        xr |j                  dk(         |j                  }|j                  d   }$| j                     }	 !d| d|       |	j                  }
t        "|      \  }}t        |      }#j                  d|      }#j                  d|      }t        j                  }t        j                   |d      }|$|j                  <   |$|j                  <   |j#                  t%        "|t'        j(                  ||	      |             |j#                  t%        "|t&        j*                  j-                  |g|
      |             t        j.                  |
      }#j                  d|      }t1        t2        j4                        } j7                  ||fd|i       |$|j                  <   |j#                  t%        "|t'        j8                  dt2        j4                  |	      |             #j                  d|      }t        j:                  j=                  t2              $|j                  <   t'        j8                  dt2        |      }|j#                  t%        "|||             #j                  d|      }|$|j                  <   t?        |
      }|dk(  rd}t&        j*                  jA                  |||      }|j#                  t%        "|||             t&        j*                  jC                  |||gi |	      }tE        jF                  |	||      |<   |j#                  t%        "| ||             tI        |      D ]  }#j                  d|      }t        j                  }|$|j                  <   |j#                  t%        "|t'        j(                  ||      |             t'        jJ                  | |||   |      }tE        jF                  t        jL                  |	||
      |<   |j#                  |        |jO                  |       y)zCheck to see if the given "array_var" is created from a list
        of constants, and try to inline the list definition as array
        initialization.

        Extra statements produced with be appended to "stmts".
        rX   r  r   r  zinline array_var = z list_var = r  r  r+   r  r  r  r  z	$np_g_varr  z$np_typ_varboolbool_rt  T)(r   r   r   r   r   r7  r1   r   ArrayCompatiblendimr,   r  r   rq   r  r  UniTuplers   r  r   rx  rg   r]  DTyper   r  r  resolve_function_typer   r  Moduler  rq  rU   r   r#   r  r  nonerE  )%r  r   r/  r  delscallnameret_typer,   r  	array_typr  seqr?   r  r1  r5  size_typsize_tuple_typnptyper  fntyg_np_varg_nptyp_var	dtype_strnp_typ_getattr
empty_callr~   r0  	index_typsetitemr   r  r{   r5   r   r   s%                                  r9   inline_arrayz-_inline_const_arraycall.<locals>.inline_array  s    6NXa[G3Nw8NO		!!!Y./T?..
8U%:%:; #"	$hh99Q<INN+	)9nhO$Wh7Q3x>>&#.c:::!4!)'5##$GXHHTs3S:	; 	G^GG//xjc/J!	" U# ^^L#6
)%%dXK'69JK#'
 GZIIgrxxSA3H	I >>+s3!&!2!22!6yyr3'_WhcBC ..4 &J	I9cB_Wg~sKL WW\\*x.A23\O
 & 0 0Hf M	*_WiSIJ t 		"Aw4I

I&/GINN#LLBHHQ4DcJLjjIs1vsCG!'!1!1%**i2;U"DIgLL!		" 	Tr;   c                   "    e Zd ZdZd Zd Zd Zy)&_inline_const_arraycall.<locals>.Statez
        This class is used to hold the state in the following loop so as to make
        it easy to reset the state of the variables tracking the various
        statement kinds
        c                 X    g | _         g | _        g | _        g | _        g | _        d| _        y )NF)r  	dead_vars
list_itemsr/  rs  ry   rd  s    r9   rR   z/_inline_const_arraycall.<locals>.State.__init__7  s2      DN  DN DODJ DI!DMr;   c                 <    g | _         g | _        g | _        g | _        y)zV
            Resets the internal state of the variables used for tracking
            N)r  r  r  rs  rd  s    r9   resetz,_inline_const_arraycall.<locals>.State.resetG  s       DNDN DODIr;   c                     t        |j                         D cg c]  }|j                  | j                  v  c}      S c c}w )z
            Returns True if the list being analysed is used between the
            build_list and the array call.
            )r   r  r   )rQ   rH  r   s      r9   list_var_usedz4_inline_const_arraycall.<locals>.State.list_var_usedP  s1    
 $..:JKQ$..0KLLKs   >N)r   r   r   r   rR   r  r  rY   r;   r9   Stater  0  s    		" 		Mr;   r  r  rU   TN)rc   r   objectrf   r1   r   r0   r2   r  r   r  rs   r   r/  rg   rh   r  rb   r  r   rs  ry   r  r  r  r  )r}   r5   r  r   r   r  r  r@  rH  r   r   removed_varrf   r{   r   s    ````        @@r9   ra  ra    s    $$<=KKKE^ ^@%M %MN GE

 7dBII&$**bff-::??eoo5OO**4;;+;+;<KK&&t,DJJ0zz77l*KKM8<

'C1'CE$'+{{'7'7&8EOKK&&t,WW&49+<\4;;"[[%//5::G)- bff%**Ke...

!!$'/&&{3&&{3""4(??b( D % *'bii8![[--@'bff5!ZZ5??:$D)* #'EK&(EO%)EN4 
 t$KKMo7r  ..5;;2d2[ (Ds   O
)NNNNNNNT)FF)Ur   r_  r   rb  numba.core.analysisr   r0  r   r   r   r   r   r	   r
   r1  r   numba.core.ir_utilsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    numba.core.imputilsr!   numba.core.extendingr"   numba.core.typingr#   numba.cpython.listobjr%   numba.cpython.rangeobjr&   numba.np.arrayobjr'   r(   numba.np.unsafe.ndarrayr)   r  r  r  r  numba.misc.specialrm   r:   rH   r  rJ   r   r   r   r  rc   rn   r  r	  rh  r  r  r  r  r  rt   r  rv   r  register_rewriteRewriter[  ra  rY   r;   r9   <module>r     s]      ! ! ! 0    *  3 * ' 2 1 (  K     AGF GT0Q+6 Q+h EI?CIM)-\#~BJ

'? #,9.1bD 8& 8&v KP!Up5|(~7
 ,-8++  .,M3r;   