U
    iâËda	  ã                   @   sf   d dl Zd dlZd dlmZmZmZmZ dd„ Zdd„ Z	dd„ Z
G d	d
„ d
ejƒZedkrbe ¡  dS )é    N)ÚtypesÚutilsÚcompilerÚregistryc                 C   s   | S ©N© ©Úxr   r   úQ/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/tests/test_wrapper.pyÚoverhead   s    r   c                 C   s   d| d< d| d< d S )Né   r   é   r   r   r   r   r
   Úarray_overhead   s    r   c                 C   s   | |  |  |  |  S r   r   r   r   r   r
   Úadd   s    r   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚTestWrapperc                    s˜   t  ttjg¡}|j‰ t t¡‰ˆ |¡ d‰‡fdd„}‡ ‡fdd„}‡‡fdd„}t	tƒ t	t
j|dd	�ƒ t	t
j|dd	�ƒ t	t
j|dd	�ƒ d
S )zW
        This will show higher overhead due to unboxing in the native version.
        éA  c                      s   t ˆ ƒ d S r   )r   r   r   r   r
   Úpython    s    z)TestWrapper.test_overhead.<locals>.pythonc                      s   ˆ ˆƒ d S r   r   r   ©Úcfuncr	   r   r
   Úpycfunc#   s    z*TestWrapper.test_overhead.<locals>.pycfuncc                      s   ˆ ˆƒ d S r   r   r   ©Údispr	   r   r
   Ú
overloaded&   s    z-TestWrapper.test_overhead.<locals>.overloadedç      à?©ZmaxsecN)r   Úcompile_isolatedr   r   Úint32Úentry_pointr   ÚCPUDispatcherÚadd_overloadÚprintr   Ú	benchmark©ÚselfÚcrr   r   r   r   ©r   r   r	   r
   Útest_overhead   s    

zTestWrapper.test_overheadc                    sÂ   t  ttjddd… g¡}|j‰ t t¡‰ˆ |¡ |  	|j
jd jd¡ tjddd�‰‡fdd	„}‡ ‡fd
d„}‡‡fdd„}ttƒ ttj|dd�ƒ ttj|dd�ƒ ttj|dd�ƒ dS )z€
        The time to set two array element seems to be more expensive than
        the overhead of the overloaded call.
        Nr   r   ÚCr   r   )ÚshapeZdtypec                      s   t ˆ ƒ d S r   )r   r   r   r   r
   r   <   s    z/TestWrapper.test_array_overhead.<locals>.pythonc                      s   ˆ ˆƒ d S r   r   r   r   r   r
   r   ?   s    z0TestWrapper.test_array_overhead.<locals>.pycfuncc                      s   ˆ ˆƒ d S r   r   r   r   r   r
   r   B   s    z3TestWrapper.test_array_overhead.<locals>.overloadedr   r   )r   r   r   r   r   r   r   r   r   ÚassertEqualÚ	signatureÚargsZlayoutÚnpZzerosr    r   r!   r"   r   r%   r
   Útest_array_overhead.   s    

zTestWrapper.test_array_overheadc                    s˜   t  ttjg¡}|j‰ t t¡‰ˆ |¡ d‰‡fdd„}‡ ‡fdd„}‡‡fdd„}t	tƒ t	t
j|dd	�ƒ t	t
j|dd	�ƒ t	t
j|dd	�ƒ d
S )zu
        This seems to be about the amount of work to balance out the overhead
        by the overloaded one
        r   c                      s   t ˆ ƒ d S r   )r   r   r   r   r
   r   W   s    z$TestWrapper.test_add.<locals>.pythonc                      s   ˆ ˆƒ d S r   r   r   r   r   r
   r   Z   s    z%TestWrapper.test_add.<locals>.pycfuncc                      s   ˆ ˆƒ d S r   r   r   r   r   r
   r   ]   s    z(TestWrapper.test_add.<locals>.overloadedr   r   N)r   r   r   r   r   r   r   r   r   r    r   r!   r"   r   r%   r
   Útest_addK   s    

zTestWrapper.test_addN)Ú__name__Ú
__module__Ú__qualname__r&   r-   r.   r   r   r   r
   r      s   r   Ú__main__)Únumpyr,   ZunittestZ
numba.corer   r   r   r   r   r   r   ZTestCaser   r/   Úmainr   r   r   r
   Ú<module>   s   S