U
    ?h                     @   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NumbaValueError)localcpuc                       s   e Zd Z fddZ  ZS )_TargetRegistryc                    sV   zt  |W S  tk
rP   d}ddd t D }t|||d Y nX d S )Nz7No target is registered against '{}', known targets:
{}
c                 S   s&   g | ]\}}|d d d| qS )z <
   z ->  ).0kvr   r   M/var/www/html/venv/lib/python3.8/site-packages/numba/core/target_extension.py
<listcomp>   s   z/_TargetRegistry.__getitem__.<locals>.<listcomp>)super__getitem__KeyErrorjointarget_registryitemsr   format)selfitemmsgZ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__'   s    ztarget_override.__enter__c                 C   s   | j t_d S r,   )r)   r'   r%   )r   tyvaltbr   r   r   __exit__*   s    ztarget_override.__exit__N)r    r!   r"   __doc__r+   r.   r2   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    r4   c                 C   sP   t | jjdkr| jd j}ntt d}|dkrHd}t||n|S d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 {}.)	lenZ	callstack_stackr%   r   getr4   
ValueErrorr   )contextr%   r   r   r   r   get_local_target4   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_strF   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_strK   s    r?   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   )ZtyctxZhwstrreasonZhw_clazzr>   r   r   r   _get_local_target_checkedQ   s
    
rB   c                   @   s   e Zd Zedd ZdS )JitDecoratorc                 C   s   t S r,   )NotImplementedr-   r   r   r   __call__p   s    zJitDecorator.__call__N)r    r!   r"   r   rE   r   r   r   r   rC   n   s   rC   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   r@   x   s    zTarget.inherits_fromN)r    r!   r"   r3   classmethodr@   r   r   r   r   rF   u   s   rF   c                   @   s   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"   r3   r   r   r   r   rK   ~   s   rK   c                   @   s   e Zd ZdZdS )CPUzMark the target as CPU.
    NrL   r   r   r   r   rM      s   rM   c                   @   s   e Zd ZdZdS )GPUzOMark the target as GPU, i.e. suitable for compilation on a GPU
    target.
    NrL   r   r   r   r   rN      s   rN   c                   @   s   e Zd ZdZdS )CUDAzMark the target as CUDA.
    NrL   r   r   r   r   rO      s   rO   c                   @   s   e Zd ZdZdS )NPyUfunczMark the target as a ufunc
    NrL   r   r   r   r   rP      s   rP   ZgenericZgpucudaZnpyufunc)Zkey_typeN)#abcr   r   Znumba.core.registryr   r   Znumba.core.decoratorsr   Znumba.core.errorsr   r   	threadingr	   tlsr'   r(   r   r   Zjit_registryobjectr$   r4   r:   r<   r?   rB   rC   rF   rK   rM   rN   rO   rP   r=   Z
cpu_targetr   r   r   r   <module>   sD   	
