a
    ==ic                     @   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 i ejdd Zef i ejdd Zef i 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   n/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/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   )	min_value	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   sn   t jdddgdgdd}dd }tjd	d
dtj}tg dg d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   )
r   r   r"   r+   randnr1   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g ddgdd}dd }tjddtj}tg d	g d
g dg}tjdtj}| |||||g| d S )Nr   r   indicesvaluesr   Z	index_putr   c                 S   s   || |< | fS r   r   r9   r   r   r   r   c   s    z$TestATen.test_index_put.<locals>.refr2   )TTT)TFF)TTF   )	r   r   r"   r+   r4   r1   r5   r6   r   )r   r   r   r   r   r7   r/   r;   r   r   r   test_index_put[   s    zTestATen.test_index_putc                 C   sR   t jddgdgdddd}dd }tg d	}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_indexrA   Zreturn_counts)r"   unique)r   r0   _r   r   r   r   x   s    z!TestATen.test_unique.<locals>.ref)r   r   r<   r3   r   r2   r   )r   r   r"   r6   printr   )r   r   r   r   r   r7   r   r   r   test_uniquem   s    	zTestATen.test_uniqueN)__name__
__module____qualname__r   huZtensorsZgcsr   r"   float16Zgcs_gpu_onlyr   r$   stZintegersr,   r.   r8   r=   rE   r   r   r   r   r   	   s    






r   __main__)Zcaffe2.pythonr   Z
hypothesisr   Z"caffe2.python.hypothesis_test_utilpythonZhypothesis_test_utilrI   Zhypothesis.strategies
strategiesrK   numpyr"   ZHypothesisTestCaser   rF   Zunittestmainr   r   r   r   <module>   s   x