
    Ng                     P    d dl Zd dlZd dlmZ d dlmZ d Z G d de          ZdS )    N)Base)expectc                    t          j        | |          }t          j        | |          }|r,t          j        ||          }t          j        ||          }t          j        |t          j        |          |          }t          j        |t          j        |          |          }|t          j        |t           j                  fS )N)axisdtype)npargsortsortfliptakearangearrayint64)Xkr   largestsorted_indicessorted_valuestopk_sorted_indicestopk_sorted_valuess           \/var/www/html/ai-engine/env/lib/python3.11/site-packages/onnx/backend/test/case/node/topk.pytopk_sorted_implementationr      s    Z---NGAD)))M :d;;;D999'.")A,,TJJJ	!4HHHrx(;28LLLLL    c                   V    e Zd Zedd            Zedd            Zedd            ZdS )TopKreturnNc                  L   d} d}d}t           j                            dddgddg|           }t          j        g d	g d
g dgt          j                  }t          j        |gt          j                  }t          ||| |          \  }}t          |||g||gd           d S )N      r   xr   valuesindices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_refs           r   export_top_kzTopK.export_top_k   s    {$$C:)/D4 % 
 
 H
 *
 
 
 HaS)))"<Q4"Q"Q
K 	!Q*k)B	
 	
 	
 	
 	
 	
r   c                  T   d} d}d}d}t           j                            dddgddg| ||	          }t          j        g d
g dg dgt          j                  }t          j        |gt          j                  }t          ||| |          \  }}t          |||g||gd           d S )Nr   r   r    r   r!   r   r"   r#   )r%   r&   r   r   sortedr'   r)   )r2   r1   r0   r/   r   test_top_k_smallestr4   r6   )	r   r   rB   r   r<   r   r=   r>   r?   s	            r   export_top_k_smallestzTopK.export_top_k_smallest9   s    {$$:y) % 
 
 H
 *
 
 
 HaS)))"<Q4"Q"Q
K 	q6-&		
 	
 	
 	
 	
 	
r   c                  L   d} d}d}t           j                            dddgddg| 	          }t          j        g d
g dg dgt          j                  }t          j        |gt          j                  }t          ||| |          \  }}t          |||g||gd           d S )Nr   r    r   r!   r   r"   r#   r$   r'   r)   r.   r   test_top_k_negative_axisr4   r6   r;   s           r   export_top_k_negative_axiszTopK.export_top_k_negative_axisd   s    {$$C:)/D4 % 
 
 H
 *
 
 
 HaS)))"<Q4"Q"Q
K 	q6-+		
 	
 	
 	
 	
 	
r   )r   N)__name__
__module____qualname__staticmethodr@   rD   rH    r   r   r   r      st        
 
 
 \
@ (
 (
 (
 \(
T !
 !
 !
 \!
 !
 !
r   r   )	numpyr	   r7   onnx.backend.test.case.baser   onnx.backend.test.case.noder   r   r   rM   r   r   <module>rQ      s   
      , , , , , , . . . . . .M M Mo
 o
 o
 o
 o
4 o
 o
 o
 o
 o
r   