
    J/Ph):                        d Z ddlZddlZddlZddlZddlmZ ddlmZm	Z	m
Z
mZ ddlmZ  G d de          Z G d d	e          Z ed
          Zej        Zej        Zej        Zej        Zej        Zej        Zej        Zd Zd Zd Zd Zd Zd Z G d de          Z  G d de          Z!d"dZ"d Z#d Z$d Z% ej&        dd          Z'ej(        d             Z)d Z*d Z+d Z,ej(        d#d             Z-d! Z.dS )$z<
Utilities to simplify the boilerplate for native lowering.
    N)Enum)typingtypesutilscgutils)BaseRegistryLoaderc                   P    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd ZdS )Registryz?
    A registry of function and attribute implementations.
    unspecifiedc                 Z    || _         g | _        g | _        g | _        g | _        g | _        d S N)name	functionsgetattrssetattrscasts	constants)selfr   s     S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/core/imputils.py__init__zRegistry.__init__   s0    	
    c                       fd}|S )a1  
        Decorate an implementation of *func* for the given argument types.
        *func* may be an actual global function object, or any
        pseudo-function supported by Numba, such as "getitem".

        The decorated implementation has the signature
        (context, builder, sig, args).
        c                 B    j                             | f           | S r   )r   append)implargtysfuncr   s    r   decoratez Registry.lower.<locals>.decorate%   s%    N!!4v"6777Kr    )r   r   r   r   s   ``` r   lowerzRegistry.lower   s/    	 	 	 	 	 	 	 r   c                 Z     ||||          }|                     |||j        f           |S r   )r   	signature)r   r   tyattr	impl_list	decorator	real_impls          r   _decorate_attrzRegistry._decorate_attr*   s8    IdB--	)T9+>?@@@r   c                       fd}|S )z
        Decorate an implementation of __getattr__ for type *ty* and
        the attribute *attr*.

        The decorated implementation will have the signature
        (context, builder, typ, val).
        c                 J                         | j        t                    S r   )r(   r   _decorate_getattrr   r$   r   r#   s    r   r   z(Registry.lower_getattr.<locals>.decorate7   (    &&tRt}'8: : :r   r   r   r#   r$   r   s   ``` r   lower_getattrzRegistry.lower_getattr/   /    	: 	: 	: 	: 	: 	: 	: r   c                 .    |                      |d          S )a:  
        Decorate the fallback implementation of __getattr__ for type *ty*.

        The decorated implementation will have the signature
        (context, builder, typ, val, attr).  The implementation is
        called for attributes which haven't been explicitly registered
        with lower_getattr().
        N)r/   r   r#   s     r   lower_getattr_genericzRegistry.lower_getattr_generic<        !!"d+++r   c                       fd}|S )z
        Decorate an implementation of __setattr__ for type *ty* and
        the attribute *attr*.

        The decorated implementation will have the signature
        (context, builder, sig, args).
        c                 J                         | j        t                    S r   )r(   r   _decorate_setattrr,   s    r   r   z(Registry.lower_setattr.<locals>.decorateO   r-   r   r   r.   s   ``` r   lower_setattrzRegistry.lower_setattrG   r0   r   c                 .    |                      |d          S )a;  
        Decorate the fallback implementation of __setattr__ for type *ty*.

        The decorated implementation will have the signature
        (context, builder, sig, args, attr).  The implementation is
        called for attributes which haven't been explicitly registered
        with lower_setattr().
        N)r8   r2   s     r   lower_setattr_genericzRegistry.lower_setattr_genericT   r4   r   c                       fd}|S )z
        Decorate the implementation of implicit conversion between
        *fromty* and *toty*.

        The decorated implementation will have the signature
        (context, builder, fromty, toty, val).
        c                 D    j                             | ff           | S r   )r   r   )r   fromtyr   totys    r   r   z%Registry.lower_cast.<locals>.decorateg   s'    Jtfd^4555Kr   r   )r   r=   r>   r   s   ``` r   
lower_castzRegistry.lower_cast_   s/    	 	 	 	 	 	 	 r   c                       fd}|S )z
        Decorate the implementation for creating a constant of type *ty*.

        The decorated implementation will have the signature
        (context, builder, ty, pyval).
        c                 B    j                             | ff           | S r   )r   r   )r   r   r#   s    r   r   z)Registry.lower_constant.<locals>.decorates   s$    N!!4"-000Kr   r   )r   r#   r   s   `` r   lower_constantzRegistry.lower_constantl   s)    	 	 	 	 	 	 r   c                     d| j          dS )NzLowering Registry<>)r   r   s    r   __repr__zRegistry.__repr__x   s    0DI0000r   N)r   )__name__
__module____qualname____doc__r   r    r(   r/   r3   r8   r:   r?   rB   rF   r   r   r   r
   r
      s                
  	, 	, 	,  	, 	, 	,  
 
 
1 1 1 1 1r   r
   c                       e Zd ZdZdZdS )RegistryLoaderz6
    An incremental loader for a target registry.
    )r   r   r   r   r   N)rG   rH   rI   rJ   registry_itemsr   r   r   rL   rL   |   s           QNNNr   rL   builtin_registryc                 D    | |fd}nfd}|f|_         ||_        |S )Nc                       | |||          S r   r   contextbuildertypvaluer$   r'   s        r   resz_decorate_getattr.<locals>.res   s    9WgsE:::r   c                 "     | ||||          S r   r   rQ   s        r   rV   z_decorate_getattr.<locals>.res   s    9WgsE4@@@r   )r"   r$   r   r#   r$   rV   r'   s       @r   r+   r+      sa    I	; 	; 	; 	; 	; 	;	A 	A 	A 	A 	A ECMCHJr   c                 Z    | |fd}nfd}|t           j        f|_        ||_        |S )Nc                       | |||          S r   r   rR   rS   sigargsr$   r'   s        r   rV   z_decorate_setattr.<locals>.res   s    9WgsD999r   c                 "     | ||||          S r   r   r[   s        r   rV   z_decorate_setattr.<locals>.res   s    9WgsD$???r   )r   Anyr"   r$   rX   s       @r   r7   r7      se    I	: 	: 	: 	: 	: 	:	@ 	@ 	@ 	@ 	@ OCMCHJr   c                    t          |j        t          j                  r|j        j        }|                     ||          }t          j        ||          }|                    |	                    |j
                            5  |                     |||          }|                    ||           d d d            n# 1 swxY w Y   |                    |          }|S r   )
isinstancereturn_typer   Optionaltypemake_optional_noner   alloca_once_valueif_thennot_is_nonemake_optional_valuestoreload)	rR   rS   r\   statusretval
value_typeoptional_none	retvalptroptional_values	            r   fix_returning_optionalrs      s   #/5>22 	)_)
227JGG-g}EE	__W\\&.99:: 	5 	5$88V N MM.)444		5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5
 i((Ms   .B>>CCc                 R      fd} j         |_        t          |          |_        |S )zC
    A wrapper inserting code calling Numba-compiled *fndesc*.
    c                 F   |                      |j                  }| j                            ||j        j        |          \  }}t          j        ||j                  5  | j        	                    ||           d d d            n# 1 swxY w Y   |j
        j        k    sJ t          | ||||          }|j        |                     |j
                  k    r/d}t          |                    |j        |j
                            t!          | |j        |          S )Nz$function returned {0} but expect {1})declare_functionmodule	call_convcall_functionrestypeargtypesr   if_unlikelyis_errorreturn_status_propagaterb   rs   rd   get_value_type	TypeErrorformatimpl_ret_new_ref)	rR   rS   r\   r]   r   rm   rn   msgfndescs	           r   impzuser_function.<locals>.imp   s]   ''?? *88T6>6?DB B &/:: 	G 	G55gvFFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G&.0000'#vvNN;'00AAAA8CCJJv{CODDEEE&.&IIIs   "B

BB)r{   r"   tuplelibs)r   r   r   s   `  r   user_functionr      s>    
J J J J J" OCMT{{CHJr   c                 :      fd}t          |          |_        |S )zD
    A wrapper inserting code calling Numba-compiled *gendesc*.
    c                     |                      |j                  }| j                            ||j        j        |          \  }}||fS r   )rv   rw   rx   ry   rz   r{   )rR   rS   r\   r]   r   rm   rn   gendescs          r   r   zuser_generator.<locals>.imp   sT    ''@@ *88T7?G,<dD D v~r   )r   r   )r   r   r   s   `  r   user_generatorr      s0    
     T{{CHJr   c                     fd}|S )zl
    Decorator a given class as implementing *iterator_type*
    (by providing an `iternext()` method).
    c                       j         t          t          j                   fd            } t	          d          |            S )Nc                 B    |\  } | ||          } || ||          S r   r   )	rR   rS   r\   r]   resultrU   iterobjclsiternexts	          r   iternext_wrapperz8iterator_impl.<locals>.wrapper.<locals>.iternext_wrapper   s3    HUc'7E22G8GWgv>>>r   r   )r   iternext_implRefTypeBORROWEDlower_builtin)r   r   r   iterator_types   ` @r   wrapperziterator_impl.<locals>.wrapper   sb    <	w'	(	(	? 	? 	? 	? 	? 
)	(	?
 	1j-001ABBB
r   r   )iterable_typer   r   s    ` r   iterator_implr      s#         Nr   c                   <    e Zd ZdZdZd Zd ZddZd Zd Z	d	 Z
d
S )_IternextResultzb
    A result wrapper for iteration, passed by iternext_impl() into the
    wrapped function.
    _context_builder_pairobjc                 0    || _         || _        || _        d S r   r   )r   rR   rS   pairobjs       r   r   z_IternextResult.__init__  s    r   c                 d    | j                             t          j        d          | j        _        dS )z1
        Mark the iterator as exhausted.
        FNr   get_constantr   booleanr   secondrE   s    r   set_exhaustedz_IternextResult.set_exhausted	  s(      $}99%-OOr   Tc                 p    |dv r%| j                             t          j        |          }|| j        _        dS )z
        Mark the iterator as valid according to *is_valid* (which must
        be either a Python boolean or a LLVM inst).
        )FTNr   )r   is_valids     r   	set_validz_IternextResult.set_valid  s8    
 }$$}11%-JJH'r   c                     || j         _        dS )zP
        Mark the iterator as yielding the given *value* (a LLVM inst).
        Nr   first)r   rU   s     r   yield_z_IternextResult.yield_  s     $r   c                 l    | j                             | j        t          j        | j        j                  S )z>
        Return whether the iterator is marked valid.
        )r   get_argument_valuer   r   r   r   r   rE   s    r   r   z_IternextResult.is_valid  s2     }//05040DF F 	Fr   c                     | j         j        S )z>
        Return the iterator's yielded value, if any.
        r   rE   s    r   yielded_valuez_IternextResult.yielded_value&  s     }""r   N)T)rG   rH   rI   rJ   	__slots__r   r   r   r   r   r   r   r   r   r   r      s          5I     
P P P( ( ( ($ $ $F F F# # # # #r   r   c                   $    e Zd ZdZ	 dZ	 dZ	 dZdS )r   z&
    Enumerate the reference type
             N)rG   rH   rI   rJ   NEWr   	UNTRACKEDr   r   r   r   r   ,  s<          C H IIIr   r   c                 V      d t           D             vrt          d           fd}|S )a  
    Wrap the given iternext() implementation so that it gets passed
    an _IternextResult() object easing the returning of the iternext()
    result pair.

    ref_type: a numba.targets.imputils.RefType value, the reference type used is
    that specified through the RefType enum.

    The wrapped function will be called with the following signature:
        (context, builder, sig, args, iternext_result)
    c                     g | ]}|S r   r   ).0xs     r   
<listcomp>z!iternext_impl.<locals>.<listcomp>I  s    +++a+++r   z3ref_type must be an enum member of imputils.RefTypec                       fd}|S )Nc                 h   |j         }|                     ||          } | |||t          | ||                     t          j        k    rt
          }n?t          j        k    rt          }n't          j        k    rt          }nt          d           || |||                                          S )NzUnknown ref_type encountered)rb   make_helperr   r   r   r   r   impl_ret_borrowedr   impl_ret_untracked
ValueError	_getvalue)	rR   rS   r\   r]   	pair_typer   impl_retr   ref_types	          r   r   z-iternext_impl.<locals>.outer.<locals>.wrapperM  s    I))'9==GD'3'::< < <7;&&+W---,W...- !?@@@8GW$-w/@/@/B/BD D Dr   r   )r   r   r   s   ` r   outerziternext_impl.<locals>.outerL  s/    	D 	D 	D 	D 	D 	D r   )r   r   )r   r   s   ` r   r   r   =  sN     ++7+++++NOOO    " Lr   c                 |    t          j        |j        |          }|                     d|          } |||f          S )z
    Call the `getiter()` implementation for the given *iterable_type*
    of value *val*, and return the corresponding LLVM inst.
    getiter)r   r"   r   get_function)rR   rS   r   valgetiter_siggetiter_impls         r   call_getiterr   `  sB    
 "=#>NNK''	;??L<#(((r   c                    |j         }t          j        |t          j                  }t	          j        ||          }|                     d|          } |||f          }|                     |||          }t          | ||          S )z
    Call the `iternext()` implementation for the given *iterator_type*
    of value *val*, and return a convenience _IternextResult() object
    reflecting the results.
    r   )	
yield_typer   Pairr   r   r"   r   r   r   )	rR   rS   r   r   itemtyr   iternext_sigr   r   s	            r   call_iternextr   j  s     %F
65=11I#I}==L((\BBM
-#
(
(C!!'9c::G7GW555r   c                     	 |                      t          t          j        t          j        |                    } |||f          S # t          $ r Y dS w xY w)z^
    Call len() on the given value.  Return None if len() isn't defined on
    this type.
    N)r   lenr   r"   r   intpNotImplementedError)rR   rS   r#   r   len_impls        r   call_lenr   y  se    
)''V-=ej"-N-NOO x#(((    tts   8A 
AA_ForIterLoop)rU   do_breakc              #      	K   |j         }t          | ||          }                    d          }                    d          		fd}                    |                               |          5  t          | ||          }                                        |                                          d          5                      	           ddd           n# 1 swxY w Y   t          |
                                |          V                      |           ddd           n# 1 swxY w Y                       	           | j        r| j                            ||           dS dS )z
    Simulate a for loop on the given iterable.  Yields a namedtuple with
    the given members:
    - `value` is the value being yielded
    - `do_break` is a callable to early out of the loop
    zfor_iter.bodyzfor_iter.endc                  2                                     d S r   )branch)bb_endrS   s   r   r   zfor_iter.<locals>.do_break  s    vr   F)likelyN)r   r   append_basic_blockr   
goto_blockr   rg   rh   r   r   r   position_at_end
enable_nrtnrtdecref)
rR   rS   r   r   r   itervalbb_bodyr   rV   r   s
    `       @r   for_iterr     s	      "/M7G]C@@G((99G''77F      NN7			G	$	$    GWmWEE__W\\#,,..99%_HH 	# 	#NN6"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#3,,..99999w                              F### <7M7;;;;;< <s7   8AD9C)D9)C-	-D90C-	1<D99D= D=c                     |S )z5
    The implementation returns a new reference.
    r   ctxrS   rettyrets       r   r   r     	     Jr   c                 L    | j         r| j                            |||           |S )z
    The implementation returns a borrowed reference.
    This function automatically incref so that the implementation is
    returning a new reference.
    )r   r   increfr   s       r   r   r     s+     ~ ,ws+++Jr   c                     |S )z.
    The return type is not a NRT object.
    r   r   s       r   r   r     r   r   numpyc              #      K   ddl m} | j        }|                    ||           | _        	 dV  || _        dS # || _        w xY w)z7
    Temporarily change the context's error model.
    r   )callconvN)
numba.corer   error_modelcreate_error_model)rR   
model_namer   old_error_models       r   force_error_modelr    sj      
 $#####)O"55j'JJG.-o----s	   9 	Ac                       t          d          )zPA stub for use internally by Numba when a call is emitted
    on a TypeRef.
    z%This function should not be executed.)r   )r]   kwargss     r   numba_typeref_ctorr    s     E
F
FFr   r   )r   )/rJ   collections
contextlibinspect	functoolsenumr   r   r   r   r   r   numba.core.typing.templatesr   objectr
   rL   rN   r    r   r/   r3   r8   r:   r?   rB   r+   r7   rs   r   r   r   r   r   r   r   r   r   
namedtupler   contextmanagerr   r   r   r   r  r  r   r   r   <module>r     s   
                    4 4 4 4 4 4 4 4 4 4 4 4 : : : : : :i1 i1 i1 i1 i1v i1 i1 i1XQ Q Q Q Q' Q Q Q 8.//  & .(>  .(> (
!0        6  "  ,-# -# -# -# -#f -# -# -#^    d   "       F) ) )6 6 6
) 
) 
) &{%n&;= = < < <<       . . . .G G G G Gr   