
    J/Ph}L              	          d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZmZ d dlmZmZmZmZmZmZ d dlmZ d dlmZ d d	lmZmZm Z m!Z! d d
l"m#Z# d dl$m%Z% d Z&dddZ'i dddfdZ(d Z)d Z*d Z+d Z,d Z-d Z. G d de%          Z/d Z0d Z1d Z2d Z3 G d d ej4        d d!g                    Z5 G d" d# ej4        d#d$d!g                    Z6d% Z7dS )&    N)typeserrorsutilsconfig)typeof_impl)as_numba_type)inferinfer_getattr)lower_builtinlower_getattrlower_getattr_genericlower_setattrlower_setattr_generic
lower_cast)models)register_default)boxunboxreflectNativeValue_import_cython_function)ReduceMixinc                      ddl mmm t	                     s$t           t                    st          d          	  j        n# t          $ r t                     Y nw xY w fd}|S )z
    Decorate a function as implementing typing for the callable *func*.
    *func* can be a callable object (probably a global) or a string
    denoting a built-in operation (such 'getitem' or '__array_wrap__')
    r   )CallableTemplater	   infer_globalz%`func` should be a function or stringc                       fd}d}f}t          |          }t          |||          } 	|           t                    r 
t          j        |                      S )Nc                 $     | j                   S N)context)selftyping_funcs    T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/numba/core/extending.pygenericz0type_callable.<locals>.decorate.<locals>.generic(   s    ;t|,,,    _CallableTemplate)keyr$   )dicttypecallabler   Function)r"   r$   namebases
class_dicttemplater   func	func_namer	   r   s   `     r#   decorateztype_callable.<locals>.decorate'   s    	- 	- 	- 	- 	- )2		3!#dG444
eZ00hD>> 	9Lu~h77888r%   )
numba.core.typing.templatesr   r	   r   r*   
isinstancestr	TypeError__name__AttributeError)r0   r2   r   r1   r	   r   s   ` @@@@r#   type_callabler9      s    ; ; ; ; ; ; ; ; ; ;D>> A*T3"7"7 A?@@@M		   II			         Os   A A('A(T)no_cpython_wrappernopythonneverFc                     	 ddl mm t                                          		                    |            	fd}|S )a	  
    A decorator marking the decorated function as typing and implementing
    *func* in nopython mode.

    The decorated function will have the same formal parameters as *func*
    and be passed the Numba types of those parameters.  It should return
    a function implementing *func* for the given types.

    Here is an example implementing len() for tuple types::

        @overload(len)
        def tuple_len(seq):
            if isinstance(seq, types.BaseTuple):
                n = len(seq)
                def len_impl(seq):
                    return n
                return len_impl

    Compiler options can be passed as an dictionary using the **jit_options**
    argument.

    Overloading strictness (that the typing and implementing signatures match)
    is enforced by the **strict** keyword argument, it is recommended that this
    is set to True (default).

    To handle a function that accepts imprecise types, an overload
    definition can return 2-tuple of ``(signature, impl_function)``, where
    the ``signature`` is a ``typing.Signature`` specifying the precise
    signature to be used; and ``impl_function`` is the same implementation
    function as in the simple case.

    If the kwarg inline determines whether the overload is inlined in the
    calling function and can be one of three values:
    * 'never' (default) - the overload is never inlined.
    * 'always' - the overload is always inlined.
    * a function that takes two arguments, both of which are instances of a
      namedtuple with fields:
        * func_ir
        * typemap
        * calltypes
        * signature
      The first argument holds the information from the caller, the second
      holds the information from the callee. The function should return Truthy
      to determine whether to inline, this essentially permitting custom
      inlining rules (typical use might be cost models).

    The *prefer_literal* option allows users to control if literal types should
    be tried first or last. The default (`False`) is to use non-literal types.
    Implementations that can specialize based on literal values should set the
    option to `True`. Note, this option maybe expanded in the near future to
    allow for more control (e.g. disabling non-literal types).

    **kwargs prescribes additional arguments passed through to the overload
    template. The only accepted key at present is 'target' which is a string
    corresponding to the target that this overload should be bound against.
    r   )make_overload_templater   c                      | 	fi }t          |           t                    r t          j        |                     | S r   )r	   r*   r   r+   )
overload_funcr/   r0   r   inlinekwargsr>   optsprefer_literalstricts
     r#   r2   zoverload.<locals>.decorate   sn    ))$tV*0.L LDJL LhD>> 	9Lu~h77888r%   )r3   r>   r   _overload_default_jit_optionscopyupdate)
r0   jit_optionsrE   rA   rD   rB   r2   r   r>   rC   s
   ` ```` @@@r#   overloadrJ   >   s    t QPPPPPPP )--//DKK
            Or%   c                       fd}r|S  ||  S )a  
    Register a regular python function that can be executed by the python
    interpreter and can be compiled into a nopython function when referenced
    by other jit'ed functions.  Can be used as::

        @register_jitable
        def foo(x, y):
            return x + y

    Or, with compiler options::

        @register_jitable(_nrt=False) # disable runtime allocation
        def foo(x, y):
            return x + y

    c                 r                          dd          }t           |d           fd            } S )NrA   r<   F)rI   rA   rE   c                      S r    )argsrB   fns     r#   ov_wrapz/register_jitable.<locals>.wrap.<locals>.ov_wrap   s    Ir%   )poprJ   )rP   rA   rQ   rB   s   `  r#   wrapzregister_jitable.<locals>.wrap   sR    Hg..	"&	F	F	F	 	 	 	 
G	F		r%   rN   )rO   rB   rS   s    ` r#   register_jitablerT      s7    "      tT{r%   c                 *     ddl m  fd}|S )a  
    A decorator marking the decorated function as typing and implementing
    attribute *attr* for the given Numba type in nopython mode.

    *kwargs* are passed to the underlying `@overload` call.

    Here is an example implementing .nbytes for array types::

        @overload_attribute(types.Array, 'nbytes')
        def array_nbytes(arr):
            def get(arr):
                return arr.size * arr.itemsize
            return get
    r   ) make_overload_attribute_templatec                 h     | fi }t          |            t          | fi |            | S r   )r
   rJ   )r@   r/   attrrB   rV   typs     r#   r2   z$overload_attribute.<locals>.decorate   s_    33}
 

 
 	h)))&))-888r%   )r3   rV   )rY   rX   rB   r2   rV   s   ``` @r#   overload_attributerZ      sJ      MLLLLL        Or%   c                 *     ddl m  fd}|S )z=Common code for overload_method and overload_classmethod
    r   )make_overload_method_templatec                                                      } | f|                    dd          |                    dd          d|}t          |            t          | fi |            | S )NrA   r<   rD   F)rA   rD   )rG   rR   r
   rJ   )r@   copied_kwargsr/   rX   rB   r\   rY   s      r#   r2   z)_overload_method_common.<locals>.decorate   s    00}
 $$Xw77(,,-=uEE
 
 	
 
 	h)))&))-888r%   )r3   r\   )rY   rX   rB   r2   r\   s   ``` @r#   _overload_method_commonr_      sJ     JIIIII
 
 
 
 
 
 
 
 Or%   c                     t          | |fi |S )a  
    A decorator marking the decorated function as typing and implementing
    method *attr* for the given Numba type in nopython mode.

    *kwargs* are passed to the underlying `@overload` call.

    Here is an example implementing .take() for array types::

        @overload_method(types.Array, 'take')
        def array_take(arr, indices):
            if isinstance(indices, types.Array):
                def take_impl(arr, indices):
                    n = indices.shape[0]
                    res = np.empty(n, arr.dtype)
                    for i in range(n):
                        res[i] = arr[indices[i]]
                    return res
                return take_impl
    )r_   rY   rX   rB   s      r#   overload_methodrb      s    ( #377777r%   c                 B    t          t          j        |           |fi |S )ak  
    A decorator marking the decorated function as typing and implementing
    classmethod *attr* for the given Numba type in nopython mode.


    Similar to ``overload_method``.


    Here is an example implementing a classmethod on the Array type to call
    ``np.arange()``::

        @overload_classmethod(types.Array, "make")
        def ov_make(cls, nitems):
            def impl(cls, nitems):
                return np.arange(nitems)
            return impl

    The above code will allow the following to work in jit-compiled code::

        @njit
        def foo(n):
            return types.Array.make(n)
    )r_   r   TypeRefra   s      r#   overload_classmethodre      s&    0 #5=#5#5tFFvFFFr%   c                 \   	
 ddl m} ddlm ddlm ddlm
 ddlm	 t           t                    rt           t          j                  st          d           fd	t            G 	 fd	d
|                      }t#                     	
fd            }dS )z
    Make an automatic attribute wrapper exposing member named *struct_attr*
    as a read-only attribute named *python_attr*.
    The given *typeclass*'s model must be a StructModel subclass.
    r   )AttributeTemplate)default_manager)StructModel)impl_ret_borrowed)cgutilsz)typeclass should be a Type subclass, got c                                          |           }t          |          st          d|          |                              S )zF
        Get the Numba type of member *struct_attr* in *typ*.
        zImake_struct_attribute_wrapper() needs a type with a StructModel, but got )lookupr4   r6   get_member_fe_type)rY   modelri   rh   struct_attrs     r#   get_attr_fe_typez0make_attribute_wrapper.<locals>.get_attr_fe_type   sa      &&s++%-- 	I)@EH I I I''444r%   c                        e Zd ZZ fdZdS )/make_attribute_wrapper.<locals>.StructAttributec                 *    |k    r |          S d S r   rN   )r!   rY   rX   rq   python_attrs      r#   generic_resolvez?make_attribute_wrapper.<locals>.StructAttribute.generic_resolve.  s'    {""'',,, #"r%   N)r7   
__module____qualname__r'   rv   )rq   ru   	typeclasss   r#   StructAttributers   *  s8        	- 	- 	- 	- 	- 	- 	- 	-r%   rz   c                                           |          | ||          } |          }t          |	          } | |||          S )N)value)create_struct_proxygetattr)
r    builderrY   valattrtyattrvalrk   rq   rj   rp   s
         r#   struct_getattr_implz3make_attribute_wrapper.<locals>.struct_getattr_impl2  s]    .g))#..wsKKK!!#&&#{++  '67CCCr%   N)r3   rg   numba.core.datamodelrh   numba.core.datamodel.modelsri   numba.core.imputilsrj   
numba.corerk   r4   r)   
issubclassr   Typer6   r
   r   )ry   rp   ru   rg   rz   r   ri   rk   rh   rq   rj   s   ```   @@@@@r#   make_attribute_wrapperr     sj    >=====444444777777555555""""""i&& (jEJ.O.O (i$9' ( ( 	(5 5 5 5 5 5 5 - - - - - - - - -+ - - ]- 9k**D D D D D D D +*D D Dr%   c                       e Zd ZdZ ej                    Z ej        e	j
                  ZdZddZed             Zd Zd Zd	 Zd
 Zd Zd Zed             ZdS )
_Intrinsicz&
    Dummy callable for intrinsic
    )maxlenNFc                 h    || _         || _        || _        || _        t	          j        | |           d S r   )_ctor_kwargs_name_defn_prefer_literal	functoolsupdate_wrapper)r!   r,   defnrD   rB   s        r#   __init__z_Intrinsic.__init__E  s9    "

- t,,,,,r%   c                     | j         }|5t          t          j                              }|                     |           |S )z
        An instance-specific UUID, to avoid multiple deserializations of
        a given instance.

        Note this is lazily-generated, for performance reasons.
        )_Intrinsic__uuidr5   uuiduuid1	_set_uuidr!   us     r#   _uuidz_Intrinsic._uuidL  s:     K9DJLL!!ANN1r%   c                 n    | j         J || _         | | j        |<   | j                            |            d S r   )r   _memo_recentappendr   s     r#   r   z_Intrinsic._set_uuidZ  s>    {"""
1D!!!!!r%   c                     ddl m}m}  || | j        | j        | j        | j                  }t          |            || t          j	        |                     d S )Nr   )make_intrinsic_templater   )rD   rB   )
r3   r   r   r   r   r   r   r	   r   r+   )r!   r   r   r/   s       r#   	_registerz_Intrinsic._register`  s    	? 	? 	? 	? 	? 	? 	? 	? +*4TZ:>:N262CE E E 	hT5>(3344444r%   c                 J    d                     |           }t          |          )zP
        This is only defined to pretend to be a callable from CPython.
        z {0} is not usable in pure-python)formatNotImplementedError)r!   rO   rB   msgs       r#   __call__z_Intrinsic.__call__k  s%     177==!#&&&r%   c                 6    d                     | j                  S )Nz<intrinsic {0}>)r   r   r!   s    r#   __repr__z_Intrinsic.__repr__r  s     ''
333r%   c                     | S r   rN   )r!   memos     r#   __deepcopy__z_Intrinsic.__deepcopy__u  s	     r%   c                 D    t          | j        | j        | j                  S )4
        NOTE: part of ReduceMixin protocol
        )r   r,   r   )r(   r   r   r   r   s    r#   _reduce_statesz_Intrinsic._reduce_statesz  s     $*4:FFFFr%   c                     	 | j         |         S # t          $ r;  | ||          }|                                 |                    |           |cY S w xY w)r   )r,   r   )r   KeyErrorr   r   )clsr   r,   r   llcs        r#   _rebuildz_Intrinsic._rebuild  sj    
	9T?" 	 	 	#4d+++CMMOOOMM$JJJ		s    AAA)F)r7   rw   rx   __doc__weakrefWeakValueDictionaryr   collectionsdequer   FUNCTION_CACHE_SIZEr   r   r   propertyr   r   r   r   r   r   r   classmethodr   rN   r%   r#   r   r   :  s          (G'))E  kv'ABBBGF- - - -   X" " "	5 	5 	5' ' '4 4 4  
G G G 
 
 [
 
 
r%   r   c                  ,    fds |  S fd}|S )au  
    A decorator marking the decorated function as typing and implementing
    *func* in nopython mode using the llvmlite IRBuilder API.  This is an escape
    hatch for expert users to build custom LLVM IR that will be inlined to
    the caller.

    The first argument to *func* is the typing context.  The rest of the
    arguments corresponds to the type of arguments of the decorated function.
    These arguments are also used as the formal argument of the decorated
    function.  If *func* has the signature ``foo(typing_context, arg0, arg1)``,
    the decorated function will have the signature ``foo(arg0, arg1)``.

    The return values of *func* should be a 2-tuple of expected type signature,
    and a code-generation function that will passed to ``lower_builtin``.
    For unsupported operation, return None.

    Here is an example implementing a ``cast_int_to_byte_ptr`` that cast
    any integer to a byte pointer::

        @intrinsic
        def cast_int_to_byte_ptr(typingctx, src):
            # check for accepted types
            if isinstance(src, types.Integer):
                # create the expected type signature
                result_type = types.CPointer(types.uint8)
                sig = result_type(types.uintp)
                # defines the custom code generation
                def codegen(context, builder, signature, args):
                    # llvm IRBuilder code here
                    [src] = args
                    rtype = signature.return_type
                    llrtype = context.get_value_type(rtype)
                    return builder.inttoptr(src, llrtype)
                return sig, codegen
    c                     t          | dt          |                     }t          || fi }|                                 |S )Nr7   )r~   r5   r   r   )r0   r,   r   rB   s      r#   
_intrinsiczintrinsic.<locals>._intrinsic  sC    tZT33t..v..
r%   c                      |           S r   rN   )r0   r   s    r#   wrapperzintrinsic.<locals>.wrapper  s    :d###r%   rN   )rO   rB   r   r   s    ` @r#   	intrinsicr     sS    J      z4  	$ 	$ 	$ 	$ 	$r%   c                 "    t          | |          S )z
    Get the address of a Cython function.

    Args
    ----
    module_name:
        Name of the Cython module
    function_name:
        Name of the Cython function

    Returns
    -------
    A Python int containing the address of the function

    r   )module_namefunction_names     r#   get_cython_function_addressr     s      #;>>>r%   c                      t           j                            t           j                            t          j                            } t           j                            |           }|S )z*Returns the C include directory path.
    )ospathdirnamenumba__file__abspath)include_dirr   s     r#   include_pathr     s?     '//"'//%."A"ABBK7??;''DKr%   c                 j      j         |i |}t                      }d}t          |j                                                  D ]=\  }\  }}	||v r1|                    |           t          |	t          j                  sd}>|r.t          j
        |          }
 fd}|
                    |          dS )aD  Ensures that the given argument types (in *args* and *kwargs*) are
    literally typed for a function with the python signature *pysig* and the
    list of literal argument names in *literal_args*.

    Alternatively, this is the same as::

        SentryLiteralArgs(literal_args).for_pysig(pysig).bind(*args, **kwargs)
    FTc                 j     j         | i |j                                        }t          |          S r   )bind	argumentsvaluestuple)rO   rB   outpysigs      r#   foldedz#sentry_literal_args.<locals>.folded  s4    %*d-f--7>>@@C::r%   N)r   set	enumerater   itemsaddr4   r   Literalr   ForceLiteralArgbind_fold_arguments)r   literal_argsrO   rB   	boundargsrequest_posmissingikver   s   `           r#   sentry_literal_argsr     s     
D+F++I %%KGy288::;;  	6AqOOAa//  	,";//	 	 	 	 	 ##F+++	, 	,r%   c                       e Zd ZdZd Zd ZdS )SentryLiteralArgsaQ  
    Parameters
    ----------
    literal_args : Sequence[str]
        A sequence of names for literal arguments

    Examples
    --------

    The following line:

    >>> SentryLiteralArgs(literal_args).for_pysig(pysig).bind(*args, **kwargs)

    is equivalent to:

    >>> sentry_literal_args(pysig, literal_args, args, kwargs)
    c                 P    |                      t          j        |                    S )zBind the sentry to the signature of *func*.

        Parameters
        ----------
        func : Function
            A python function.

        Returns
        -------
        obj : BoundLiteralArgs
        )	for_pysigr   pysignature)r!   r0   s     r#   for_functionzSentryLiteralArgs.for_function  s!     ~~e/55666r%   c                 .    t          || j                  S )zBind the sentry to the given signature *pysig*.

        Parameters
        ----------
        pysig : inspect.Signature


        Returns
        -------
        obj : BoundLiteralArgs
        )r   r   )BoundLiteralArgsr   )r!   r   s     r#   r   zSentryLiteralArgs.for_pysig  s$      *
 
 
 	
r%   N)r7   rw   rx   r   r   r   rN   r%   r#   r   r     s<         "7 7 7
 
 
 
 
r%   r   _SentryLiteralArgsr   c                       e Zd ZdZd ZdS )r   z=
    This class is usually created by SentryLiteralArgs.
    c                 :    t          | j        | j        ||          S )z Bind to argument types.
        )r   r   r   )r!   rO   rB   s      r#   r   zBoundLiteralArgs.bind6  s'     #J	
 
 	
r%   N)r7   rw   rx   r   r   rN   r%   r#   r   r   1  s-         
 
 
 
 
r%   r   r   c                 .    ddl m} t          | |          S )zReturns True if a function is wrapped by one of the Numba @jit
    decorators, for example: numba.jit, numba.njit

    The purpose of this function is to provide a means to check if a function is
    already JIT decorated.
    r   )
Dispatcher)numba.core.dispatcherr   r4   )functionr   s     r#   	is_jittedr   A  s&     100000h
+++r%   )8r   r   r   r   r   r   r   r   r   r   r   numba.core.typing.typeofr   numba.core.typing.asnumbatyper   r3   r	   r
   r   r   r   r   r   r   r   r   r   r   register_modelnumba.core.pythonapir   r   r   r   numba._helperlibr   numba.core.serializer   r9   rF   rJ   rT   rZ   r_   rb   re   r   r   r   r   r   r   
namedtupler   r   r   rN   r%   r#   <module>r     s   				            3 3 3 3 3 3 3 3 3 3 3 3 1 0 0 0 0 0 7 7 7 7 7 7 < < < < < < < <6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 ( ' ' ' ' ' C C C C C C A A A A A A A A A A A A 4 4 4 4 4 4 , , , , , ,  D 8<,0!2 !2   "$w!K K K K\  @  <  (8 8 8.G G G6'D 'D 'DTQ Q Q Q Q Q Q Qh3 3 3l? ? ?&  , , ,>0
 0
 0
 0
 0
..~.0 0 0
 0
 0
f
 
 
 
 
-{-Wn57 7 
 
 
 
, 
, 
, 
, 
,r%   