
    xKgS                        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mZ d dl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 d dlZd dlZd d	lmZ  G d
 de      Zed        Z d Z! G d de      Z"ddZ#d Z$ ee#      d        Z%y)    N)ir)typestypingutilsr   configir_utilsregistry)CallableTemplate	signatureinfer_globalAbstractTemplate)lower_builtin)register_jitable)NumbaValueError)literal_unroll)numpy_supportc                       e Zd ZdZd Zd Zy)StencilFuncLowererzMCallable class responsible for lowering calls to a specific StencilFunc.
    c                     || _         y N)stencilFunc)selfsfs     Z/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/numba/stencils/stencil.py__init__zStencilFuncLowerer.__init__   s
        c                     | j                   j                  |j                  i |j                  d       }|j	                  ||j
                  ||      }|j                  |j                  g       |S r   )r   compile_for_argtysargsreturn_typecall_internalfndescadd_linking_libslibrary)r   contextbuildersigr   cresress          r   __call__zStencilFuncLowerer.__call__   s\    22388ROOT+##GT[[#tD  $,,0
r   N)__name__
__module____qualname____doc__r   r*    r   r   r   r      s    r   r   c                     | j                   }t        |      D ]a  }| j                  |j                  k7  rt        d      |j                   }t	        t        |            D ]  }||   ||   kD  st        d       c y )Nz\Secondary stencil array does not have same number  of dimensions as the first stencil input.zaSecondary stencil array has some dimension smaller the same dimension in the first stencil input.)shaper   ndim
ValueErrorrangelen)ar   ashapeargargshapeis         r   !raise_if_incompatible_array_sizesr;   $   s    WWF d#66SXX J K K99s6{#Aay8A;&  "2 3 3 $ $r   c                 N    t        | j                  |z   | j                  |z         S )z_ Called by stencil in Python mode to add the loop index to a
        user-specified slice.
    )slicestartstop)	the_sliceaddends     r   slice_additionrB   ;   s#     6)9>>F+BCCr   c                   P    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zy)StencilFuncz@
    A special type to hold stencil information for the IR.
    r   c                    t        |       j                  | _        t        |       xj                  dz  c_        || _        || _        || _        g | _        t        j                  j                  | _
        t        j                  j                  | _        | j                  | j                         | j
                  j                  d      | _        i | _        t#        |       | _        y )N   neighborhood)type
id_counterid	kernel_irmodeoptionskwsr	   
cpu_targettyping_context
_typingctxtarget_context
_targetctx_install_typegetrG   _type_cacher   	_lower_me)r   rK   rL   rM   s       r   r   zStencilFunc.__init__H   s    t*''T
""	 #--<<"--<<4??+ LL,,^<+D1r   c           
         g }|j                         D ]  \  }}|j                  }|j                  }g }	|j                  D ]{  }
t	        |
t
        j                        rL|j                  |       t        |      dk(  rct        j                  |||      }t        j                  ||d   |      }|	j                  t        j                  |||
j                  |             g }|D ]  }t        j                  |||      }||gz  }! |j                  d|      }t
        j                  j                  ||      }|	j                  t        j                  |||             t        j                  |||      }t        j                  |||
j                  |      }|	j                  |       k|	j                  |
       ~ |	|_         |S )z
        Find return statements in the IR and replace them with a SetItem
        call of the value "returned" by the kernel into the result array.
        Returns the block labels that contained return statements.
        rF   r   stencil_index)itemsscopelocbody
isinstancer   Returnappendr5   VarSetItemvalueredefineExprbuild_tupleAssign)r   blocks
index_varsout_name
ret_blockslabelblockr[   r\   new_bodystmtrvarivarvar_index_varsone_var	index_vars_index_var
tuple_callsis                      r   replace_return_with_setitemz'StencilFunc.replace_return_with_setitemX   sw    
"LLNLE5KKE))CH

dBII.%%e,:!+!vveXs;!vveZ]C@ 

4tzz3(OP *,'1G(*ugs(CI*yk9N (2 ',nn_c&J%'WW%8%8%M
 		*k3(OP!vveXs;  ZZk4::sK +OOD)5 #6 "EJ? +@ r   c                    i }g }	t         j                  dk\  r,t        d||       t        j                  |j
                         |d}
n)d}
t        |      |k7  rt        dt        |      |fz        t        j                  |j
                        }t               }|j
                  j                         D 	][  }|j                  }|j                  }g }|j                  D 	]'  }t        |t        j                         rt        |j"                  t        j$                        rut         j                  dk\  r5t        d|j&                  j(                  |j"                  j"                         |j"                  j"                  ||j&                  j(                  <   t        |t        j                         rht        |j"                  t        j*                        rD|j"                  j,                  dv r,|j"                  j"                  j(                  |j.                  v s<t        |t        j0                        r-|j&                  j(                  |j.                  v rt        d	      t        |t        j                         r|t        |j"                  t        j*                        rW|j"                  j,                  d
v r>|j"                  j"                  j(                  |j.                  v r|j"                  j"                  j(                  |vr|j"                  j,                  dk(  r|j"                  j2                  }n|j"                  j4                  }|j7                  |j"                  j"                  j(                         |
r]t9        |d      sJ |j(                  |v r|	||j(                     gz  }	n-|j(                  |v r|	||j(                     gz  }	nt;        d      |dk(  rt        j<                  ||d   |      }|j?                  d|      }||j(                     }t        |t@        jB                  jD                        ru|j?                  d|      }tG        jH                  tJ              }t@        jL                  jO                  |      }|||j(                  <   t        jP                  d||      }|jS                  t        j                   |||             t        j*                  jU                  |||gd|      }|jW                  | jX                  |t@        jZ                  gi       ||<   |jS                  t        j                   |||             |jS                  t        j                   t        j*                  j]                  |j"                  j"                  ||      |j&                  |             t        j*                  j_                  t`        j6                  |||      }|jS                  t        j                   |||             |jS                  t        j                   t        j*                  j]                  |j"                  j"                  ||      |j&                  |             g }g }|j?                  d|      }g }g } ||j(                     }tc        |      D ]  }!|j?                  d|      }|jS                  t        j                   t        j$                  |!|      ||             ||gz  }t        j<                  |||!   |      }||gz  }|j?                  d|      }| |gz  } |j?                  d|      }"t        j*                  j]                  |||!   |      }#|jS                  t        j                   |#|"|             t        |t@        jd                        r||!   }$n|dd }$t        |$t@        jB                  jD                        r|j?                  d|      }tG        jH                  tJ              }t@        jL                  jO                  |      }|||j(                  <   t        jP                  d||      }|jS                  t        j                   |||             t        j*                  jU                  ||"||!   gd|      }|jW                  | jX                  |$t@        jZ                  gi       ||<   |jS                  t        j                   |||             It        j*                  j_                  t`        j6                  |"||!   |      }|jS                  t        j                   |||              t        j*                  jg                  | |      }%|jS                  t        j                   |%||             |jS                  t        j                   t        j*                  j]                  |j"                  j"                  ||      |j&                  |             	|jS                  |       	* ||_        	^ |
rftc        |      D &cg c]  }&ddg }}&t        |	      dk(  rt;        d      |	D ]-  }'t        |'th              st        |'tj              rtc        t        |'            D ]  }(|'|(   })t        |)t        j<                        r|)j(                  |v r||)j(                     })t        |)tl              r1to        ||(   d   |)      ||(   d<   tq        ||(   d   |)      ||(   d<   t;        d       t        |'      }*nNt        |'tl              r3to        |d   d   |'      |d   d<   tq        |d   d   |'      |d   d<   d}*nt;        d      |*|k7  s%t;        d       ||fS c c}&w )z
        Transforms the stencil kernel as specified by the user into one
        that includes each dimension's index variable as part of the getitem
        calls.  So, in effect array[-1] becomes array[index0-1].
        rF   add_indices_to_kernelNTFD%d dimensional neighborhood specified for %d dimensional input arrayzremembering in const_dict)setitemstatic_setitemz?Assignments to arrays passed to stencil kernels is not allowed.)getitemstatic_getitemr~   namezDstencil kernel index is not constant, 'neighborhood' option requiredr   rY   rB   r/   const_indexind_stencil_indexz=Stencil kernel with no accesses to relatively indexed arrays.zCstencil kernel index is not constant,'neighborhood' option requiredz/Non-tuple or non-integer used as stencil index.z2Stencil index does not match array dimensionality.)9r   DEBUG_ARRAY_OPTprintr   dump_blocksrh   r5   r3   get_tuple_tablesetvaluesr[   r\   r]   r^   r   rg   rc   Consttargetr   re   op	arg_namesrb   indexrt   addhasattrr   ra   rd   r   misc	SliceTypenumbanjitrB   	functions
DispatcherGlobalr`   callget_call_typerQ   intpr~   binopoperatorr4   
ConstSizedrf   tuplelistintminmax)+r   kernelindex_namesr2   rG   standard_indexedtypemap	calltypes
const_dictkernel_constsneed_to_calc_kerneltuple_tablerelatively_indexedrm   r[   r\   rn   ro   stmt_index_varrt   tmpvarstmt_index_var_typsa_varsa_funcsa_func_typg_saslice_addition_callacc_callri   sum_resultsru   const_index_varsind_stencilsdim
getitemvargetitemcallone_index_typrv   _r   r:   te	index_lens+                                              r   rz   z!StencilFunc.add_indices_to_kernel   s	    
!!Q&)4>  /"&"'< D(  ".14\1BD0I"J K K ..v}}= U]]))+EKKE))CH

tRYY/tzz2884--294;;;K;K"jj..0 48::3C3CJt{{//0bii0&tzz277; JJMM-JJ JJ,,11V5E5EEtRZZ0 KK,,0@0@@$ &2 3 3tRYY/&tzz277; JJMM-JJ JJ,,11V5E5EE JJ,,119IIzz}}	1)-)9)9)-)=)= '**4::+;+;+@+@A +&~v>>>)..+=)k.:M:M.N-OOM+00J>)j9L9L.M-NNM"1 3K #L L qy
 %'FF5+a.#$F	!&!E-4^5H5H-I* &&8%**:N:NO%*^^4Dc%JF&+jj&@G*///*D*DW*MK3>GFKK0#%99-=w#LD$OOBIIdFC,HI24'',,vXaGbdfhk2l/=H=V=VW[WfWfi{  ~C  ~H  ~H  iI  KM  >NI&9:$OOBII6I6SV,WX$OOBII+-77??4::;K;KVUX+Y+/;;-= > (*ww}}X\\>5>(EH$OOBIIh,LM$OOBII+-77??4::;K;KVUX+Y+/;;-= > &(
&(&+nn_c&J+-(')-4^5H5H-I* $);C%*^^M3%GF$OOBIIbhhsC6H6<c-C D,8,(*uk#6F(LI&9+5J%*^^4G%MF(VH4L).	3)GJ*,''//.7G7Lc+SK$OOBIIk:s,ST)*<e>N>NO0B30G0B10E  *-9M9MN).8H#)N*/**^*D.3oo.H.H.Q7B 4')yy1A7C'P (		$0L M68ggll6JXbcfXgKhjlnq6r 3ALAZAZ[_[j[jmz  }B  }G  }G  mH  JL  BM	*= > (		:MvWZ0[ \+-77==z9CC#,O (		(FC0P QG $/J &(WW%8%8s%K
 		*k3(OP 		"$''//$**2B2B;s"S"&++c)3 4 OOD)G #H "EJQ ,T  ,1;7;aQqE;L7=!Q&% 'C D D 'eU+z%/F"3u:."1X%b"&&1bgg6K!+BGG!4B%b#.14\!_Q5G1LLOA.14\!_Q5G1LLOA."1!A#B B / !$E
Is+),\!_Q-?)GLOA&),\!_Q-?)GLOA& !I)IK K$)LN N- '2 011= 8s   $nc                 R   t         j                  dk\  r5t        d|       t        j                  | j
                  j                         t        |d   t        j                  j                        st        d      ddlm} |j                  | j                  | j                   | j
                  |d i       \  }}}}t        |t        j                  j                        rt        d      t        j                  j                  ||d   j"                  |d   j$                        }|||fS )NrF   get_return_typer   zGThe first argument to a stencil kernel must be the primary input array.)typed_passesz:Stencil kernel must return a scalar and not a numpy array.)r   r   r   r   r   rK   rh   r^   r   npytypesArrayr   
numba.corer   type_inference_stagerQ   rS   r2   layout)r   argtysr   r   r    r   r   real_rets           r   r   zStencilFunc.get_return_typeJ  s   !!Q&#V,  !6!67&)U^^%9%9:! #@ A A 	,-9-N-N.*i k5>>#7#78!LN N >>''VAY^^5;AY5E5EG'9--r   c                     t        dt        | j                        z   t        ft	        | | j
                              }|j                  | |       y)zmConstructs and installs a typing class for a StencilFunc object in
        the input typing context.
        StencilFuncTyping_)keygenericN)rH   strrJ   r   dict_type_meinsert_user_function)r   	typingctx_ty_clss      r   rT   zStencilFunc._install_typec  sG     +477|$(*dmm<> 	&&tW5r   c                 \    | j                   |   \  }}}} | j                  |||||g| }	|	S r   )rV   _stencil_wrapper)
r   r   kwtysr    sigretr   resultr   r   new_funcs
             r   r   zStencilFunc.compile_for_argtysm  sG    *.*:*:6*B'FGY(4(()0)F>DFr   c                 0   | j                   Ut        | j                         |d   j                  k7  r0t        dt        | j                         |d   j                  fz        |}d}d}d|v r||d   fz  }|dz  }|d   }d|v r||d   fz  }|dz  }|| j                  v r| j                  |   \  }}}}|S | j                  |      \  }}	}
t        |g| }d	j                  d
j                  | j                  j                        |      }t        |      t               v t               f t        d      }|j                  t!        j"                  |            }| j$                  j'                  | j(                  | |fg       |||	|
f| j                  |<   |S )z
        Implement AbstractTemplate.generic() for the typing class
        built by StencilFunc._install_type().
        Return the call-site signature.
        Nr   r{    outz
, out=NonerG   z, neighborhood=Nonez*def __numba_dummy_stencil({}{}):
    pass
,__numba_dummy_stencil)pysig)rG   r5   r2   r   rV   r   r   formatjoinrK   r   execglobalslocalsevalreplacer   pysignaturerS   insert_func_defnrW   )r   r   r   argtys_extra	sig_extrar   _sigr   r   r   r   r'   
dummy_text
dummy_funcs                 r   r   zStencilFunc._type_met  s    )!!"fQinn4! #C#&t'8'8#96!9>>"J#K L L 	E>U5\O+L%I5\FU"U>244L..I 4+++"..|<OT1aK)-)=)=f)E&7I0<0DKK!9!9:IG
ZGI%vx/12
kk 1 1* =k>((4>>4*N)OP*-vw	)J&
r   c                    i } |j                          }i |_        |j                  j                         D ]  \  }}t        j                  |j                  |         }g |_        |j                  |   j                  D ]?  }t        j                  |      }	|j                  j                  |	       ||v s8||   ||	<   A ||j                  |<    ||fS )a  
        Create a copy of a given IR along with its calltype information.
        We need a copy of the calltypes because copy propagation applied
        to the copied IR will change the calltypes and make subsequent
        uses of the original IR invalid.
        )copyrh   rZ   deepcopyr]   r`   )
r   r   r   copy_calltypeskernel_copyblock_labelrm   	new_blockro   scopys
             r   copy_ir_with_calltypesz"StencilFunc.copy_ir_with_calltypes  s     bggi$&IIOO$5 [%bii&<=IIN		+.33
 d+%%e,9$,5dON5) 4 /8K{+ %6 ^,,r   c           
         | j                  | j                  |      \  }}t        j                  |j                         |j
                  d   }	t        j                  |j                  |      \  }
}t        j                  |j                        }t        j                  |j                  |
|||       d|v rt        d      t        j                  d|      }t        j                  dk\  rt        d||       |d   }t        j                  dk\  rKt        d||j                  t        |j                        |       t        j                   |j                         dt#        t%        |            j'                  d	d
      d
| j$                  }g }t)        |j*                        D ]*  }t        j                  dt-        |      z   |      }||gz  }, t        j                  d|      }t        j                  d|      }d}||dj/                  |      z  }dt1        | j2                        v r|dj/                  |      z  }| j4                  j7                  dg       }|	|v rt        d      t9        t;        |      t;        |j
                        z
        dk7  rt        d      | j=                  |||j*                  | j>                  |||      \  }}| j>                  || _        t        j                  dk\  r*t        d       t        j                   |j                         | jA                  |j                  ||      }t        j                  dk\  r+t        d|       t        j                   |j                         dj/                  |djC                  |j
                        |      }g }t)        |j*                        D ]`  }tE        ||   d   tF              r||   d   }||   d   }n$dj/                  ||      }dj/                  ||      }|jI                  ||f       b t9        |      dkD  r"|d|	z   z  }|D ]  }||	k7  s	|d|z   z  } |dz  }t        j                  d|      }|dj/                  ||	      z  }d } |tK        jL                  |j                        j                  jN                  }!dj/                  |||!      }"d| j4                  v ra| j4                  d   }#tP        jR                  jS                  |#      }$| jT                  jW                  |$|j                        sd}%t        |%      d}#|d |"z   z  }t)        |j*                        D ]  }&d!g|j*                  z  }'d!g|j*                  z  }(d"j/                  | j>                  |&   d         |'|&<   d#j/                  | j>                  |&   d         |(|&<   |d d$j/                  |djC                  |'       | |#            z   z  }|d d$j/                  |djC                  |(       | |#            z   z  } nd| j4                  v r| j4                  d   }#tP        jR                  jS                  |#      }$| jT                  jW                  |$|j                        sd}%t        |%      d%j/                  | | |#            }"|d |"z   z  }d})t)        |j*                        D ]C  }t)        |)      D ]  }*|d z  }	 |d&j/                  ||   ||   d   ||||   d         z  }|)dz  })E t)        |)      D ]  }*|d z  }	 |d'j/                  |      z  }|d(j/                  |      z  }t        j                  dk\  rt        d)       t        |       tY        |      t[               v t]               f t_        |      }+|ta        jb                  |+      },|,|_2        dd*l3m4}- |-jk                  |+      }.t        jl                  |.j                         t        j                  |.j                        }/i }0||||g|j
                  z   |z   }1|/jo                         D ]e  \  }2}3|2|1vstE        |3tp        jr                        sJ |3jt                  jw                  |3jx                  |3jz                        }4|4jx                  |0|2<   g t        j|                  |.j                  |0       t        |.j                  j                               dz   }5t        j                  |j                  |5      |_        t        |j                  j                               dz   }6|D 7cg c]  }7|7|5z   	 }}7t        j                  dk\  rat        d+||5       t        d,       t        j                   |.j                         t        d-       t        j                   |j                         |.j                  jo                         D ]  \  }8}9t        |9j                        D ]d  \  }}:tE        |:tp        j                        s"|:j                  jx                  |k(  s<|:jz                  };|9jt                  }<tq        j                  |<|;      }=|9j                  d | |=_C        |9j                  |dz   d  |9_C        t        |j                  j                               }>|=jI                  tq        j                  |>|;             |j                  jo                         D ]  \  }?}@|@|.j                  |?<    |9|.j                  |6<   |=|.j                  |8<   |D ]4  }A|.j                  |A   jI                  tq        j                  |6|;             6  n  n t        j                  |.j                        |._        t        jl                  |.j                         tE        |t        j                        sJ |}Bt        |B      }Ct        j                  dk\  r+t        d.C       t        j                   |.j                         t        j                  |.j                         |-j                  | jT                  | j                  |.Cd |-j                  i       }D|DS c c}7w )/Nr   r   z6Cannot use the reserved word 'out' in stencil kernels.__sentinel__rF   name_var_tabler   __numba_stencil_-r   r   rG   r   z	, {}=Nonestandard_indexingzYThe first argument to a stencil kernel must use relative indexing, not standard indexing.z[Standard indexing requested for an array name not present in the stencil kernel definition.zAfter add_indices_to_kernelz!After replace_return_with_setitemzdef {}({}{}):
r   z	{}[{}][0]z	{}[{}][1]z&    raise_if_incompatible_array_sizes(z)

full_shapez    {} = {}.shape
c                     t        j                  |       s3t        j                  |       ryt        j                  |       r| dk  ryyy t	        |       S )Nznp.nanr   z-np.infznp.inf)npisfiniteisnanisinfr   )cvals    r   cval_as_strz1StencilFunc._stencil_wrapper.<locals>.cval_as_strB  sE    ;;t$88D>#XXd^ax('	 $ 4y r   z{} = np.empty({}, dtype=np.{})
r  z-cval type does not match stencil return type.z    :z:-{}z-{}:z{}[{}] = {}
z{}[:] = {}
z.for {} in range(-min(0,{}),{}[{}]-max(0,{})):
z{} = 0
z    return {}
znew stencil func textcompilerzret_blocks w/ offsetsz"before replace sentinel stencil_irz#before replace sentinel kernel_copynew_stencil_param_types)Qr   rK   r   remove_argsrh   r   copy_propagateget_name_var_tableapply_copy_propagater   get_unused_var_namer   r   r   dtyperH   r   hexrJ   r   r4   r2   r   r   r   rN   rM   rU   r5   r   rz   rG   rx   r   r^   r   r`   r   as_dtyper+   r   typeofrQ   can_convertr   r   r   r   r   r   r   r   r  run_frontendremove_delsrZ   r   ra   r[   rd   r   r\   replace_var_namesr   keysadd_offset_to_labels	enumerater]   rg   r   Blockr   Jumprename_labelsr   Typer   fixup_var_define_in_scope
compile_irrS   DEFAULT_FLAGS)Er   r   r   r    r   r   r   r   r   	first_argin_cpsout_cpsr   sentinel_name	the_arraystencil_func_nameri   r:   index_var_namerj   neighborhood_namer   r   kernel_sizer   rk   	func_textrangeslohiother_array
shape_namer  return_type_nameout_initr  cval_tymsgr   start_items	end_itemsoffsetjstencil_funcr   r  
stencil_ir	var_tablenew_var_dictreserved_namesr   varnew_varstencil_stub_last_label	new_labelxrl   rm   instr\   r[   
prev_blockbody_first_labellb	ret_blockarray_typesr  r   sE                                                                        r   r   zStencilFunc._stencil_wrapper  s   & )-(C(C,0NNI)G%n 	[//0))!,	"11+2D2DgN!44[5G5GH%%	 N"!"Z[[ 44^^T!!Q&"NMBG	!!Q&$k;3D3D&*;+<+<&=tE  !3!34
 ),ByM(:(B(B3(L(,1 
y~~&A%99'CF:J:HJN>**J ' //~F$889GI	++H55IT$((^+++,=>>I  <<++,?D((! #R S S s#$s;+@+@'AABaG! #R S S +/*D*DZ!!#3Wn+N'' $ +D!!Q&/0  !3!34 55k6H6H6@(L
 !!Q&5zB  !3!34 &,,->!6!67D	 y~~&A+a.+S1 ^A& ^A& ''(91= ''(91=MM2r(# ' !"Q&AIMMI1)+{!22I  2 I 11,O
*11*iHH		!  >,55*00 226$xx 8?? *.>@H %||F+ --..t4227K<M<MNIC)#..(**IY^^,"einn4 EINN2	#)==1B1B31G1J#KC !'t/@/@/Ea/H!I	#Vo&<&<XsxxP[G\^ijn^o&ppp	Vo&<&<XsxxPYGZ\ghl\m&nnn	 - %||F+ --..t4227K<M<MNIC)#..)00;t;LMVh..	y~~&A6]V#	 #  128&&qM"1IaL&"1IaL3**I aKF' '* vAI 
 	Z&&}55	&--h77	!!Q&)*) 	Y79$fh.-.%%l3E FL'**<8
Z../ //
0A0AB	((4E%')4)>)>?AKL"*ID#>)!#rvv...)),,SXXsww?%,\\T"	 +
 	"":#4#4lC"%j&7&7&<&<&>"?!"C &:: + 2 24KM**//12Q6	;EF:aa11:
F!!Q&):7NO67  !2!2378  !3!34 '--335LE5$UZZ04bii0KK$$5((C!KKE
 "$%!5J&+jj!nJO!&AEF!3EJ'*;+=+=+B+B+D'E$ %%bgg.>&DE #."4"4":":"<A/0
))!, #= 49J%%i0/9J%%e, &0	")))4;;GGIs35 &0 C 1F K 6N %22:3D3DE
Z../)UZZ010"&{"3!!Q&+-DE  !2!23 	**:+<+<=&&OOOO#"" Q Gs   7qc                 4   | j                   j                          | j                  `t        | j                        |d   j                  k7  r;t        dj                  t        | j                        |d   j                              d|v r|d   }|j                  }t        j                  |      }t        j                  j                  ||j                  t        j                  |            }t        |D cg c]!  }t        j                   j!                  |      # c}      }t        |D cg c]!  }t        j                   j!                  |      # c}|gz         }	n:d }t        |D cg c]!  }t        j                   j!                  |      # c}      }|}	t"        j$                  dk\  rt'        d|||       | j)                  |      \  }
}} | j*                  |d |
||g|	 }| |j,                  | S  |j,                  ||fz    S c c}w c c}w c c}w )Nr   zD{} dimensional neighborhood specified for {} dimensional input arrayr   rF   r*   )rQ   refreshrG   r5   r2   r3   r   r  r   
from_dtyper   r   r   
map_layoutr   r   r  r   r   r   r   r   entry_point)r   r   kwargsr   rdtyperttyperesult_typer?  rF  array_types_fullr   r   r   r   s                 r   r*   zStencilFunc.__call__  s   !)!!"d1gll2 77=v #D$5$5 6Q8FG G F?E]F\\F"--f5F....vv{{/</G/G/OQK$ G$Q!5!5a!8$ GHK$t%Lt!fmm&:&:1&=t%L&1]&3  4 F$ G$Q!5!5a!8$ GHK*!!Q&*k48)-)=)=k)J&7I(4((x)2G5EG >'8''..'8''$y.::% !H%L !Hs   8&H.&H+&HN)r+   r,   r-   r.   rI   r   rx   rz   r   rT   r   r   r   r   r*   r/   r   r   rD   rD   A   sF     J2 (TE2P.26&P-6EN
 ;r   rD   c                     t        | t              sd}| }n| }d }|D ]  }|dvst        d|z          t        ||      }| ||      S |S )Nconstant)r  r   rG   zUnknown stencil option )r^   r   r3   _stencil)func_or_moderM   rL   funcoptionwrappers         r   stencilrX     sg    lC(FF6?@@  tW%Gt}Nr   c                 <      dk7  rt        d z          fd}|S )NrR  zUnsupported mode style c                 L    ddl m} |j                  |       }t        |      S )Nr   r  )r   r  r  rD   )rU  r  rK   rL   rM   s      r   	decoratedz_stencil.<locals>.decorated6  s%    '))$/	9dG44r   )r3   )rL   rM   r[  s   `` r   rS  rS  2  s)    z2T9::5
 r   c                     t        j                  t        j                  t        j                  j
                        d      S )z lowering for dummy stencil callsr   )lirConstantIntTyper   r   bitwidth)r%   r&   r'   r   s       r   stencil_dummy_lowerra  =  s(     <<EJJ$7$78!<<r   )rR  )&r   numpyr   llvmliter   r]  r   r   r   r   r   r   r	   numba.core.typing.templatesr
   r   r   r   numba.core.imputilsr   numba.core.extendingr   numba.core.errorsr   numba.misc.specialr   r   r   numba.npr   objectr   r;   rB   rD   rX  rS  ra  r/   r   r   <module>rk     s       K K KI I - 1 - -   "  3 3,D];& ];~$	 w= =r   