o
    ۾i                     @   s|  d dl mZmZ d dlmZmZ d dlmZ d dlm	Z	m
Z
 d dlmZ e ZdZG dd deZe Ze ZG d	d
 d
eZdd Zdd Zdd Zdd Zdd ZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZ eed#< eed< eed< eed< eed$< eed < eed%< e ed&< eed'Z!ed Z"ee!e"< eee"< d(S ))    )ABCabstractmethod)DelayedRegistryCPUDispatcher)jit)InternalTargetMismatchErrorNonexistentTargetError)localcpuc                       s   e Zd Z fddZ  ZS )_TargetRegistryc                    sL   zt  |W S  ty%   d}ddd t D }t|||d w )Nz7No target is registered against '{}', known targets:
{}
c                 S   s&   g | ]\}}|d d d| qS )z <
   z ->  ).0kvr   r   O/home/ubuntu/.local/lib/python3.10/site-packages/numba/core/target_extension.py
<listcomp>   s    z/_TargetRegistry.__getitem__.<locals>.<listcomp>)super__getitem__KeyErrorjointarget_registryitemsr   format)selfitemmsgknown	__class__r   r   r      s   
z_TargetRegistry.__getitem__)__name__
__module____qualname__r   __classcell__r   r   r   r   r      s    r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	target_overridezWContext manager to temporarily override the current target with that
       prescribed.c                 C   s   t tdt| _|| _d S )Ntarget)getattr_active_context_active_context_default_orig_targetr&   )r   namer   r   r   __init__#   s   
ztarget_override.__init__c                 C   s   | j t_ d S N)r&   r(   r   r   r   r   	__enter__(      ztarget_override.__enter__c                 C   s   | j t_d S r-   )r*   r(   r&   )r   tyvaltbr   r   r   __exit__+   r0   ztarget_override.__exit__N)r!   r"   r#   __doc__r,   r/   r4   r   r   r   r   r%       s
    r%   c                   C   s   t tdtS )zReturns the current target
    r&   )r'   r(   r)   r   r   r   r   current_target/   s   r6   c                 C   sJ   t | jjdkr| jd j}ntt d}|du r#d}t|||S )za
    Gets the local target from the call stack if available and the TLS
    override if not.
    r   Nz7The target found is not registered.Given target was {}.)	len	callstack_stackr&   r   getr6   
ValueErrorr   )contextr&   r   r   r   r   get_local_target5   s   r=   c                 C   s   t |  S )z<Resolves a target specified as a string to its Target class.)r   )
target_strr   r   r   resolve_target_strG   s   r?   c                 C   s   t | }t| S )z6Returns the dispatcher associated with a target string)r?   dispatcher_registry)r>   	target_hwr   r   r   resolve_dispatcher_from_strL   s   rB   c                 C   s*   t |}t| }||st||||S )a  Returns the local target if it is compatible with the given target
    name during a type resolution; otherwise, raises an exception.

    Parameters
    ----------
    tyctx: typing context
    hwstr: str
        target name to check against
    reason: str
        Reason for the resolution. Expects a noun.
    Returns
    -------
    target_hw : Target

    Raises
    ------
    InternalTargetMismatchError
    )r?   r=   inherits_fromr   )tyctxhwstrreasonhw_clazzrA   r   r   r   _get_local_target_checkedR   s
   
rH   c                   @   s   e Zd Zedd ZdS )JitDecoratorc                 C   s   t S r-   )NotImplementedr.   r   r   r   __call__q   s   zJitDecorator.__call__N)r!   r"   r#   r   rK   r   r   r   r   rI   o   s    rI   c                   @   s   e Zd ZdZedd ZdS )Targetz Implements a target c                 C   s
   t | |S )zAReturns True if this target inherits from 'other' False otherwise)
issubclass)clsotherr   r   r   rC   y   s   
zTarget.inherits_fromN)r!   r"   r#   r5   classmethodrC   r   r   r   r   rL   v   s    rL   c                   @      e Zd ZdZdS )GenericzmMark the target as generic, i.e. suitable for compilation on
    any target. All must inherit from this.
    Nr!   r"   r#   r5   r   r   r   r   rR          rR   c                   @   rQ   )CPUzMark the target as CPU.
    NrS   r   r   r   r   rU      rT   rU   c                   @   rQ   )GPUzOMark the target as GPU, i.e. suitable for compilation on a GPU
    target.
    NrS   r   r   r   r   rV      rT   rV   c                   @   rQ   )CUDAzMark the target as CUDA.
    NrS   r   r   r   r   rW      rT   rW   c                   @   rQ   )NPyUfunczMark the target as a ufunc
    NrS   r   r   r   r   rX      rT   rX   genericgpucudanpyufunc)key_typeN)#abcr   r   numba.core.registryr   r   numba.core.decoratorsr   numba.core.errorsr   r   	threadingr	   tlsr(   r)   r   r   jit_registryobjectr%   r6   r=   r?   rB   rH   rI   rL   rR   rU   rV   rW   rX   r@   
cpu_targetr   r   r   r   <module>   sF    	
