U
    rh                     @  sP   d dl mZ d dlZd dlZd dlmZ d dlmZ dd Z	G dd deZ
dS )	    )annotationsN)Base)expectc                 C  s|   t j| |d}t j| |d}|r<t j||d}t j||d}t j|t ||d}t j|t ||d}|t j|t jdfS )N)axisZdtype)npZargsortsortZflipZtakeZarangearrayint64)Xkr   largestZsorted_indicesZsorted_valuesZtopk_sorted_indicesZtopk_sorted_values r   D/tmp/pip-unpacked-wheel-xnis5xre/onnx/backend/test/case/node/topk.pytopk_sorted_implementation   s    r   c                   @  sB   e Zd ZeddddZeddddZeddddZd	S )
TopKNone)returnc                  C  s   d} d}d}t jjdddgddg| d}tjd	dd
dgddddgddddggtjd}tj|gtjd}t||| |\}}t|||g||gdd d S )N      r   xr   valuesindicesinputsoutputsr   r                     	   
      r   Z
test_top_kr   r   name	onnxhelperZ	make_noder   r	   Zfloat32r
   r   r   r   r   r   noder   K
values_refindices_refr   r   r   export_top_k   s0       


   zTopK.export_top_kc            	      C  s   d} d}d}d}t jjdddgddg| ||d	}tjddd
dgddddgddddggtjd}tj|gtjd}t||| |\}}t|||g||gdd d S )Nr   r   r   r   r   r   r   r   )r   r   r   r   sortedr   r   r   r   r    r$   r#   r"   r!   r   Ztest_top_k_smallestr%   r'   )	r   r   r0   r   r+   r   r,   r-   r.   r   r   r   export_top_k_smallest:   s6    	


zTopK.export_top_k_smallestc                  C  s   d} d}d}t jjdddgddg| d	}tjd
dddgddddgddddggtjd}tj|gtjd}t||| |\}}t|||g||gdd d S )Nr   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r   Ztest_top_k_negative_axisr%   r'   r*   r   r   r   export_top_k_negative_axise   s0       


zTopK.export_top_k_negative_axisN)__name__
__module____qualname__staticmethodr/   r1   r3   r   r   r   r   r      s    *r   )
__future__r   Znumpyr   r(   Zonnx.backend.test.case.baser   Zonnx.backend.test.case.noder   r   r   r   r   r   r   <module>   s   