U
    ú¾|eª  ã                   @   sT   d Z ddlZddlZddlmZ G dd„ dƒZG dd„ dejƒZG dd	„ d	eƒZdS )
z¢
Implement utils for supporting retargeting of dispatchers.

WARNING: Features defined in this file are experimental. The API may change
         without notice.
é    N)Úerrorsc                   @   s>   e Zd ZdZejZdd„ Zdd„ Zdd„ Z	dd	„ Z
d
d„ ZdS )ÚRetargetCachez^Cache for retargeted dispatchers.

    The cache uses the original dispatcher as the key.
    c                 C   s   |   ¡ | _d| _d| _d S )Nr   )Úcontainer_typeÚ_cacheÚ	_stat_hitÚ
_stat_miss©Úself© r
   úP/var/www/website-v5/atlas_env/lib/python3.8/site-packages/numba/core/retarget.pyÚ__init__   s    
zRetargetCache.__init__c                 C   s   || j |< dS )z9Save a dispatcher associated with the given key.
        N)r   )r	   Ú	orig_dispZnew_dispr
   r
   r   Ú
save_cache   s    zRetargetCache.save_cachec                 C   s6   | j  |¡}|dkr$|  jd7  _n|  jd7  _|S )z9Load a dispatcher associated with the given key.
        Né   )r   Úgetr   r   )r	   r   Úoutr
   r
   r   Ú
load_cache   s
    zRetargetCache.load_cachec                 C   s
   | j  ¡ S )z+Returns the contents of the cache.
        )r   Úitemsr   r
   r
   r   r   (   s    zRetargetCache.itemsc                 C   s   | j | jdœS )z0Returns stats regarding cache hit/miss.
        )ÚhitÚmiss)r   r   r   r
   r
   r   Ústats-   s    zRetargetCache.statsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚweakrefÚWeakKeyDictionaryr   r   r   r   r   r   r
   r
   r
   r   r      s   
r   c                   @   s,   e Zd ZdZejdd„ ƒZejdd„ ƒZdS )ÚBaseRetargetz/Abstract base class for retargeting logic.
    c                 C   s   dS )z³Check that the retarget is compatible.

        This method does not return anything meaningful (e.g. None)
        Incompatibility is signalled via raising an exception.
        Nr
   ©r	   r   r
   r
   r   Úcheck_compatible6   s    zBaseRetarget.check_compatiblec                 C   s   dS )z²Retargets the given dispatcher and returns a new dispatcher-like
        callable. Or, returns the original dispatcher if the the target_backend
        will not change.
        Nr
   r   r
   r
   r   Úretarget?   s    zBaseRetarget.retargetN)r   r   r   r   ÚabcÚabstractmethodr   r    r
   r
   r
   r   r   3   s
   
r   c                   @   sN   e Zd ZdZeZdd„ Zeje	dœdd„ƒZ
ejdd„ ƒZd	d
„ Zdd„ ZdS )ÚBasicRetargeta¯  A basic retargeting implementation for a single output target.

    This class has two abstract methods/properties that subclasses must define.

    - `output_target` must return output target name.
    - `compile_retarget` must define the logic to retarget the given dispatcher.

    By default, this class uses `RetargetCache` as the internal cache. This
    can be modified by overriding the `.cache_type` class attribute.

    c                 C   s   |   ¡ | _d S )N)Ú
cache_typeÚcacher   r
   r
   r   r   V   s    zBasicRetarget.__init__)Úreturnc                 C   s   dS )zhReturns the output target name.

        See numba/tests/test_retargeting.py for example usage.
        Nr
   r   r
   r
   r   Úoutput_targetY   s    zBasicRetarget.output_targetc                 C   s   dS )zkReturns the retargeted dispatcher.

        See numba/tests/test_retargeting.py for example usage.
        Nr
   r   r
   r
   r   Úcompile_retargeta   s    zBasicRetarget.compile_retargetc                 C   s<   |j }| j}|dk	r8||kr8d|› d|› d�}t |¡‚dS )zt
        This implementation checks that
        `self.output_target == orig_disp._required_target_backend`
        Nz2The output target does match the required target: z != Ú.)Ú_required_target_backendr'   r   ÚCompilerError)r	   r   Zrequired_targetr'   Úmr
   r
   r   r   i   s    zBasicRetarget.check_compatiblec                 C   sR   | j }|j}| d¡| jkr |S | |¡}|dkrJ|  |¡}| ||¡ n|}|S )zgApply retargeting to orig_disp.

        The retargeted dispatchers are cached for future use.
        Útarget_backendN)r%   Útargetoptionsr   r'   r   r(   r   )r	   r   r%   ÚoptsÚcachedr   r
   r
   r   r    v   s    

zBasicRetarget.retargetN)r   r   r   r   r   r$   r   r!   ÚabstractpropertyÚstrr'   r"   r(   r   r    r
   r
   r
   r   r#   H   s   
r#   )	r   r!   r   Ú
numba.corer   r   ÚABCr   r#   r
   r
   r
   r   Ú<module>   s   &