o
    8ήc                     @   s|   d dl Z d dlmZ d dlmZmZmZmZ G dd deZ	G dd deZ
e
dZG d	d
 d
ejZG dd dejZdS )    N)TargetDescriptor)utilstyping
dispatchercpuc                   @   s"   e Zd ZdZdZejdd ZdS )_NestedContextNc              	   c   sB    | j | jf}z|| _ || _d V  W |\| _ | _d S |\| _ | _w N)_typing_context_target_context)selftyping_contexttarget_context
old_nested r   :/tmp/pip-target-vg8gfxp4/lib/python/numba/core/registry.pynested   s   z_NestedContext.nested)__name__
__module____qualname__r	   r
   
contextlibcontextmanagerr   r   r   r   r   r   	   s
    r   c                   @   sT   e Zd ZejZe Zej	dd Z
ej	dd Zedd Zedd Zd	d
 ZdS )	CPUTargetc                 C   s   t | j| jS r   )r   
CPUContextr   _target_namer   r   r   r   _toplevel_target_context   s   z"CPUTarget._toplevel_target_contextc                 C   s   t  S r   )r   Contextr   r   r   r   _toplevel_typing_context!   s   z"CPUTarget._toplevel_typing_contextc                 C      | j j}|dur
|S | jS )z5
        The target context for CPU targets.
        N)_nestedr
   r   r   r   r   r   r   r   &      zCPUTarget.target_contextc                 C   r   )z5
        The typing context for CPU targets.
        N)r   r	   r   r    r   r   r   r   1   r!   zCPUTarget.typing_contextc                 C   s   | j ||S )z
        A context manager temporarily replacing the contexts with the
        given ones, for the current thread of execution.
        )r   r   )r   r   r   r   r   r   nested_context<   s   zCPUTarget.nested_contextN)r   r   r   r   CPUTargetOptionsoptionsr   r   r   cached_propertyr   r   propertyr   r   r"   r   r   r   r   r      s    





r   r   c                   @   s   e Zd ZeZdS )CPUDispatcherN)r   r   r   
cpu_targettargetdescrr   r   r   r   r'   H   s    r'   c                       s8   e Zd ZdZ fddZ fddZ fddZ  ZS )DelayedRegistrya#  
    A unique dictionary but with deferred initialisation of the values.

    Attributes
    ----------
    ondemand:

        A dictionary of key -> value, where value is executed
        the first time it is is used.  It is used for part of a deferred
        initialization strategy.
    c                    sN   t  | _|dd | _|dd | _| jp| j| _tt| j	|i | d S )Nkey_type
value_type)
r   
UniqueDictondemandpopr+   r,   _type_checksuperr*   __init__)r   argskws	__class__r   r   r2   X   s
   
zDelayedRegistry.__init__c                    s2   || j v r| j |  | |< | j |= tt| |S r   )r.   r1   r*   __getitem__)r   itemr5   r   r   r7   _   s   
zDelayedRegistry.__getitem__c                    sL   | j rdd }| jd ur||| j | jd ur||| j tt| ||S )Nc                 S   s>   t |tr|| jv sJ | |fd S t | |sJ | |fd S r   )
isinstancetype__mro__)xty_xr   r   r   checkg   s   
z*DelayedRegistry.__setitem__.<locals>.check)r0   r+   r,   r1   r*   __setitem__)r   keyvaluer>   r5   r   r   r?   e   s   

zDelayedRegistry.__setitem__)r   r   r   __doc__r2   r7   r?   __classcell__r   r   r5   r   r*   L   s
    r*   )r   numba.core.descriptorsr   
numba.corer   r   r   r   objectr   r   r(   
Dispatcherr'   r-   r*   r   r   r   r   <module>   s    -