o
    soii                     @  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| }|r| }t j|| f|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dtype)
npindicesshapelexsortsortfliptakearangearrayint64)	Xkr   largestind_axissorted_indicessorted_valuestopk_sorted_indicestopk_sorted_values r   T/home/ubuntu/.local/lib/python3.10/site-packages/onnx/backend/test/case/node/topk.pytopk_sorted_implementation   s   r   c                   @  sn   e Zd ZedddZedddZedddZedd	d
ZedddZedddZ	edddZ
dS )TopKreturnNonec                  C     d} d}d}t jjdddgddg| d}tjg d	g d
g dgtjd}tj|gtjd}t||| |\}}t|||g||gdd d S )N      r   xr   valuesr	   inputsoutputsr   r   r!      r"                  	   
      r   
test_top_kr&   r'   name	onnxhelper	make_noder   r   float32r   r   r   r   r   r   noder   K
values_refindices_refr   r   r   export_top_k   s$   
zTopK.export_top_kc                  C  r    )Nr!   r"   r   r#   r   r$   r	   r%   r(   r*   r/   r   test_top_k_uint64r5   )	r8   r9   r:   r   r   uint64r   r   r   r<   r   r   r   export_top_k_uint64=   *   
zTopK.export_top_k_uint64c                  C  s|   d} d}d}t jjdddgddg| d}tjg d	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   test_top_k_same_valuesr5   r8   r9   r:   r   r   r   r   r   r<   r   r   r   export_top_k_same_valuesa   $   
zTopK.export_top_k_same_valuesc                  C  s|   d} d}d}t jjdddgddg| d	}tjg d
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%   rF   r   test_top_k_same_values_largestr5   rH   r<   r   r   r    export_top_k_same_values_largest}   rJ   z%TopK.export_top_k_same_values_largestc                  C  s   d} d}d}t jjdddgddg| d}tjg d	g d
g d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%   rF   )r!   r!   r!   r!   )r)   r)   r!   r!   r   test_top_k_same_values_2dr5   rH   r<   r   r   r   export_top_k_same_values_2d   s$   
z TopK.export_top_k_same_values_2dc            	      C  s   d} d}d}d}t jjdddgddg| ||d	}tjg d
g dg d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*   )r3   r2   r1   r0   r   test_top_k_smallestr5   r7   )	r   r   sorted_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g d
g dg d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   test_top_k_negative_axisr5   r7   r<   r   r   r   export_top_k_negative_axis   rE   zTopK.export_top_k_negative_axisN)r   r   )__name__
__module____qualname__staticmethodrA   rD   rI   rL   rN   rR   rU   r   r   r   r   r      s     #*r   )
__future__r   numpyr   r8   onnx.backend.test.case.baser   onnx.backend.test.case.noder   r   r   r   r   r   r   <module>   s   