3
H4W^â  ã               @   s˜   d dl mZ d dl mZ d dl mZ d dl mZ d dlmZmZ d dlm	Z	 d dl
jjZd dljZd dlZG dd	„ d	ejƒZed
kr”d dlZejƒ  dS )é    )Úabsolute_import)Údivision)Úprint_function)Úunicode_literals)ÚcoreÚdyndep)ÚgivenNc               @   sî   e Zd Zef dejdd�iej—Ždd„ ƒZef dejdej	d�iej
—Ždd„ ƒZef dejd	d�iej—Žd
d„ ƒZef dejddd�iej—Ždd„ ƒZef dejd	d�iej—Ždd„ ƒZef ejŽdd„ ƒZef ejŽdd„ ƒZdS )ÚTestATenÚinputsé   )Únc             C   s4   t jdddgdgdd�}dd„ }| j||||ƒ d S )	NÚATenÚXÚYÚZÚadd)Úoperatorc             S   s
   | | gS )N© )r   r   r   r   ú>/tmp/pip-build-e66j97b2/torch/caffe2/contrib/aten/aten_test.pyÚref   s    zTestATen.test_add.<locals>.ref)r   ÚCreateOperatorÚassertReferenceChecks)Úselfr
   ÚgcÚdcÚopr   r   r   r   Útest_add   s    zTestATen.test_add)r   Zdtypec             C   s4   t jdddgdgdd�}dd„ }| j||||ƒ d S )	Nr   r   r   r   r   )r   c             S   s
   | | gS )Nr   )r   r   r   r   r   r   $   s    z#TestATen.test_add_half.<locals>.ref)r   r   r   )r   r
   r   r   r   r   r   r   r   Útest_add_half   s    zTestATen.test_add_halfé   c             C   s4   t jddgdgddd�}dd„ }| j||||ƒ d S )	Nr   ÚSr   Úpowg       @)r   Úexponentc             S   s   t j| ƒgS )N)ÚnpZsquare)r   r   r   r   r   0   s    zTestATen.test_pow.<locals>.ref)r   r   r   )r   r
   r   r   r   r   r   r   r   Útest_pow(   s    
zTestATen.test_powÚxé   )Z	min_valueZ	max_valuec             C   sB   t jj|ƒg}tjddgddgdd�}dd„ }| j||||ƒ d S )	Nr   r   r   ÚIÚsort)r   c             S   s   t j| ƒt j| ƒgS )N)r"   r'   Zargsort)r   r   r   r   r   >   s    zTestATen.test_sort.<locals>.ref)r"   ÚrandomZpermutationr   r   r   )r   r$   r   r   r
   r   r   r   r   r   Ú	test_sort5   s    zTestATen.test_sortc             C   s2   t jddgdgdd�}dd„ }| j||||ƒ d S )Nr   r   r   Úsum)r   c             S   s   t j| ƒgS )N)r"   r*   )r   r   r   r   r   J   s    zTestATen.test_sum.<locals>.ref)r   r   r   )r   r
   r   r   r   r   r   r   r   Útest_sumB   s    zTestATen.test_sumc             C   sˆ   t jddddgdgdd�}dd	„ }tjjd
d
ƒjtjƒ}tjdddgdddgdddggƒ}tjjdƒjtjƒ}| j|||||g|ƒ d S )Nr   r   ÚindicesÚvaluesr   Z	index_put)r   c             S   s   || |< | fS )Nr   )r   r,   r-   r   r   r   r   W   s    z$TestATen.test_index_put.<locals>.refé   TFé   )	r   r   r"   r(   ZrandnZastypeZfloat32Úarrayr   )r   r   r   r   r   ÚtensorÚmaskr-   r   r   r   Útest_index_putO   s    "zTestATen.test_index_putc             C   s\   t jddgdgdddd�}dd„ }tjd	d
ddd
dd
gƒ}t||ƒƒ | j|||g|ƒ d S )Nr   r   ÚoutputTÚ_unique)ÚsortedÚreturn_inverser   c             S   s   t j| dddd�\}}|fS )NFT)Zreturn_indexr7   Zreturn_counts)r"   Úunique)r   ÚindexÚ_r   r   r   r   l   s    z!TestATen.test_unique.<locals>.refr   r   r/   é   r.   )r   r   r"   r0   Úprintr   )r   r   r   r   r   r1   r   r   r   Útest_uniquea   s    zTestATen.test_uniqueN)Ú__name__Ú
__module__Ú__qualname__r   ÚhuZtensorsZgcsr   r"   Zfloat16Zgcs_gpu_onlyr   r#   ÚstZintegersr)   r+   r3   r=   r   r   r   r   r	      s   $($&$r	   Ú__main__)Ú
__future__r   r   r   r   Zcaffe2.pythonr   r   Z
hypothesisr   Z"caffe2.python.hypothesis_test_utilÚpythonZhypothesis_test_utilrA   Zhypothesis.strategiesZ
strategiesrB   Znumpyr"   ZHypothesisTestCaser	   r>   ZunittestÚmainr   r   r   r   Ú<module>   s   
g