B
      ›\ž  ã               @   s¤   d dl mZmZmZ d dlZddlmZ ddlmZ ddlm	Z	m
Z
mZ G dd	„ d	eƒZG d
d„ deƒZeƒ ZG dd„ de	jƒZG dd„ de
jƒZeƒ Zeed< dS )é    )Úprint_functionÚdivisionÚabsolute_importNé   )Úcpu)ÚTargetDescriptoré   )Ú
dispatcherÚutilsÚtypingc               @   s"   e Zd ZdZdZejdd„ ƒZdS )Ú_NestedContextNc          	   c   s6   | j | jf}z|| _ || _d V  W d |\| _ | _X d S )N)Ú_typing_contextÚ_target_context)ÚselfÚtyping_contextÚtarget_contextZ
old_nested© r   ú5lib/python3.7/site-packages/numba/targets/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¡S )N)r   Z
CPUContextr   )r   r   r   r   Ú_toplevel_target_context   s    z"CPUTarget._toplevel_target_contextc             C   s   t  ¡ S )N)r   ZContext)r   r   r   r   Ú_toplevel_typing_context$   s    z"CPUTarget._toplevel_typing_contextc             C   s   | j j}|dk	r|S | jS dS )z5
        The target context for CPU targets.
        N)Ú_nestedr   r   )r   r   r   r   r   r   )   s    zCPUTarget.target_contextc             C   s   | j j}|dk	r|S | jS dS )z5
        The typing context for CPU targets.
        N)r   r   r   )r   r   r   r   r   r   4   s    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   ZCPUTargetOptionsZoptionsr   r   r
   Zcached_propertyr   r   Úpropertyr   r   r   r   r   r   r   r      s   r   c               @   s   e Zd ZeZdS )ÚCPUDispatcherN)r   r   r   Ú
cpu_targetZtargetdescrr   r   r   r   r    K   s   r    c                   s,   e Zd ZdZ‡ fdd„Z‡ fdd„Z‡  ZS )ÚTargetRegistrya1  
    A registry of API implementations for various backends.

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

        A dictionary of target-name -> function, where function is executed
        the first time a target is used.  It is used for deferred
        initialization for some targets (e.g. gpu).
    c                s    t t| ƒj||Ž t ¡ | _d S )N)Úsuperr"   Ú__init__r
   Ú
UniqueDictÚondemand)r   ÚargsZkws)Ú	__class__r   r   r$   [   s    zTargetRegistry.__init__c                s2   || j kr"| j | ƒ | |< | j |= tt| ƒ |¡S )N)r&   r#   r"   Ú__getitem__)r   Úitem)r(   r   r   r)   _   s    
zTargetRegistry.__getitem__)r   r   r   Ú__doc__r$   r)   Ú__classcell__r   r   )r(   r   r"   O   s   r"   r   )Z
__future__r   r   r   r   Ú r   Zdescriptorsr   r	   r
   r   Úobjectr   r   r!   Z
Dispatcherr    r%   r"   Zdispatcher_registryr   r   r   r   Ú<module>   s   -