U
    d                     @   sl   d dl mZ d dlmZ d dlm  mZ d dlm	Z
 d dlZG dd dejZedkrhd dlZe  dS )    )core)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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 }| |||| d S )	NATenXYZaddoperatorc                 S   s
   | | gS N r	   r
   r   r   A/tmp/pip-unpacked-wheel-ua33x9lu/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 }| |||| d S )	Nr   r	   r
   r   r   r   c                 S   s
   | | gS r   r   r   r   r   r   r      s    z#TestATen.test_add_half.<locals>.refr   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 }| |||| d S )	Nr   Sr   powg       @)r   exponentc                 S   s   t | gS r   )npZsquarer	   r   r   r   r   +   s    zTestATen.test_pow.<locals>.refr   r   r   r   r   test_pow#   s     zTestATen.test_powx   )Z	min_valueZ	max_valuec                 C   sB   t j|g}tjddgddgdd}dd }| |||| d S )	Nr   r   r   Isortr   c                 S   s   t | t | gS r   )r"   r(   Zargsortr#   r   r   r   r   9   s    zTestATen.test_sort.<locals>.ref)r"   randomZpermutationr   r   r   )r   r%   r   r   r   r   r   r   r   r   	test_sort0   s    zTestATen.test_sortc                 C   s2   t jddgdgdd}dd }| |||| d S )Nr   r   r   sumr   c                 S   s   t | gS r   )r"   r+   r#   r   r   r   r   E   s    zTestATen.test_sum.<locals>.refr   r   r   r   r   test_sum=   s    zTestATen.test_sumc                 C   sr   t jdddgdgdd}dd }tjd	d
dtj}tdddgdddggtj}| 	||||g| d S )Nr   r   maskr   indexr   c                 S   s   | | tj fS r   )astyper"   Zbool_)r   r-   r   r   r   r   S   s    z&TestATen.test_index_uint8.<locals>.refr         r   r   )
r   r   r"   r)   randnr/   float32arrayZuint8r   )r   r   r   r   r   tensorr-   r   r   r   test_index_uint8J   s    "zTestATen.test_index_uint8c                 C   s   t jddddgdgdd}dd	 }tjd
d
tj}tdddgdddgdddgg}tjdtj}| |||||g| d S )Nr   r   indicesvaluesr   Z	index_putr   c                 S   s   || |< | fS r   r   )r   r7   r8   r   r   r   r   c   s    z$TestATen.test_index_put.<locals>.refr0   TF   )	r   r   r"   r)   r2   r/   r3   r4   r   )r   r   r   r   r   r5   r-   r8   r   r   r   test_index_put[   s    "zTestATen.test_index_putc              	   C   s\   t jddgdgdddd}dd }td	d
ddd
dd
g}t|| | |||g| d S )Nr   r   outputT_unique)sortedreturn_inverser   c                 S   s   t j| dddd\}}|fS )NFT)Zreturn_indexr>   Zreturn_counts)r"   unique)r   r.   _r   r   r   r   x   s    z!TestATen.test_unique.<locals>.refr   r   r9   r1   r0   )r   r   r"   r4   printr   )r   r   r   r   r   r5   r   r   r   test_uniquem   s    	zTestATen.test_uniqueN)__name__
__module____qualname__r   huZtensorsZgcsr   r"   Zfloat16Zgcs_gpu_onlyr   r$   stZintegersr*   r,   r6   r:   rB   r   r   r   r   r   	   s    









r   __main__)Zcaffe2.pythonr   Z
hypothesisr   Z"caffe2.python.hypothesis_test_utilpythonZhypothesis_test_utilrF   Zhypothesis.strategiesZ
strategiesrG   Znumpyr"   ZHypothesisTestCaser   rC   Zunittestmainr   r   r   r   <module>   s   x