U
    iâËd¸  ã                   @   s„   d dl Z d dlZd dlmZmZ d dlmZ d dlZd dl	m
Z
 dd„ ZG dd„ deejƒZG d	d
„ d
eejƒZedkr€e ¡  dS )é    N)ÚnjitÚ	vectorize)ÚMemoryLeakMixin)Údufuncc                 C   s   | | S ©N© ©Úa0Úa1r   r   úY/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/numba/tests/npyufunc/test_dufunc.pyÚpyuadd   s    r   c                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )Ú
TestDUFuncc                 C   s   t j|tdd�d�S )NT)Znopython)Ztargetoptions)r   ZDUFuncÚdict)ÚselfZpyfuncr   r   r   Únopython_dufunc   s    zTestDUFunc.nopython_dufuncc              	   C   s|   |   t¡}|  |j¡ d|_|  |j¡ |  t¡� d|_W 5 Q R X |  t¡�$ |t 	ddd¡t 	ddd¡ƒ W 5 Q R X d S )NTFr   é   é
   é   )
r   r   ZassertFalseZ_frozenÚ
assertTrueÚassertRaisesÚ
ValueErrorÚ	TypeErrorÚnpÚlinspace©r   Úduaddr   r   r   Útest_frozen   s    
zTestDUFunc.test_frozenc                 C   s&   |   t¡}|  tddƒ|ddƒ¡ d S )Nr   r   )r   r   ÚassertEqualr   r   r   r   Útest_scalar   s    
zTestDUFunc.test_scalarc                    sÜ   |   t¡‰ t‡ fdd„ƒ}t ddd¡}|d d… }|dd … }t d¡}||||ƒ tj || |¡ | d¡}| d¡}t d¡}||||ƒ tj || |¡ |d d… }	t d¡}
|||	|
ƒ tj ||	 |
¡ d S )	Nc                    s   ˆ | ||ƒ d S r   r   )r	   r
   Zo0©r   r   r   Únpmadd%   s    z(TestDUFunc.test_npm_call.<locals>.npmaddr   çffffffþ?é   r   ©r   é   r$   )	r   r   r   r   r   ZzerosÚtestingÚassert_array_equalÚreshape)r   r    ÚXÚX0ÚX1Úout0ÚY0ÚY1Úout1ÚY2Úout2r   r   r   Útest_npm_call"   s$    





zTestDUFunc.test_npm_callc                    sÎ   |   t¡‰ t‡ fdd„ƒ}t ddd¡}|d d… }|dd … }|||ƒ}tj || |¡ | d¡}| d¡}|||ƒ}tj || |¡ |d d… }	|||	ƒ}
tj ||	 |
¡ |d	d
ƒ}|  |d¡ d S )Nc                    s
   ˆ | |ƒS r   r   r   r   r   r   r    ;   s    z8TestDUFunc.test_npm_call_implicit_output.<locals>.npmaddr   r!   r"   r   r#   r$   g      ð?g       @g      @)	r   r   r   r   r   r%   r&   r'   r   )r   r    r(   r)   r*   r+   r,   r-   r.   r/   r0   Zout3r   r   r   Útest_npm_call_implicit_output8   s"    






z(TestDUFunc.test_npm_call_implicit_outputc                 C   s–   |   t¡}|  |jd¡ |  |jd¡ |  |j|j|j ¡ |  |jd¡ |  |jg ¡ |  |jd ¡ |ddƒ |  |jd¡ |  |jt	|jƒ¡ d S )Nr   r   r   )
r   r   r   ZninZnoutÚnargsZntypesÚtypesÚidentityÚlenr   r   r   r   Útest_ufunc_propsM   s    

zTestDUFunc.test_ufunc_propsN)	Ú__name__Ú
__module__Ú__qualname__r   r   r   r1   r2   r7   r   r   r   r   r      s   
r   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚTestDUFuncPicklingc                    sh   t  |¡}t  |¡‰ ˆ dƒ}|  d|¡ |  ||¡ t‡ fdd„ƒ}|dƒ}|  d|¡ |  ||¡ d S )Né{   c                    s   ˆ | ƒS r   r   )Úx©Zrebuiltr   r   Úfooe   s    z%TestDUFuncPickling.check.<locals>.fooiA  )ÚpickleÚdumpsÚloadsr   ZassertIsInstancer   )r   ÚidentÚresult_typeÚbufÚrr?   r   r>   r   Úcheck[   s    

zTestDUFuncPickling.checkc                 C   s$   t dd„ ƒ}| j|ttjfd� d S )Nc                 S   s   | S r   r   ©Úx1r   r   r   rC   n   s    z3TestDUFuncPickling.test_unrestricted.<locals>.ident©rD   )r   rG   Úintr   Úinteger©r   rC   r   r   r   Útest_unrestrictedm   s    
z$TestDUFuncPickling.test_unrestrictedc                 C   s$   t dgƒdd„ ƒ}| j|td� d S )Nzfloat64(float64)c                 S   s   | S r   r   rH   r   r   r   rC   u   s    z1TestDUFuncPickling.test_restricted.<locals>.identrJ   )r   rG   ÚfloatrM   r   r   r   Útest_restrictedt   s    
z"TestDUFuncPickling.test_restrictedN)r8   r9   r:   rG   rN   rP   r   r   r   r   r;   Z   s   r;   Ú__main__)r@   Únumpyr   Znumbar   r   Znumba.tests.supportr   ZunittestZnumba.np.ufuncr   r   ZTestCaser   r;   r8   Úmainr   r   r   r   Ú<module>   s   K"