
    Si                        S SK Jr  S SKrS SKJr  S r " S S\5      r " S S\5      r " S	 S
\5      r	 " S S\5      r
g)    )annotationsN)OpRunc                4   [        U[        R                  5      (       a%  UR                  S:w  a  [	        SU< S35      eUS   n[        U5      n[        R                  " U R                  5      U   nU(       a  U* n[        R                  " X@4US9n[        R                  " XUS9nU(       a(  [        R                  " XRS9n[        R                  " XbS9n[        R                  " U5      n[        R                  " XWUS9n[        R                  " XgUS9n	X4$ )zSee function `_kneighbors_reduce_func
<https://github.com/scikit-learn/scikit-learn/blob/main/
sklearn/neighbors/_base.py#L304>`_.
   zk must be an integer not .r   axis)
isinstancenpndarraysizeRuntimeErrorintindicesshapelexsorttake_along_axisfliparangetake)
Xkr	   largestind_axissorted_indicessorted_valuesarktopk_sorted_indicestopk_sorted_valuess
             Y/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/onnx/reference/ops/op_topk.pytopk_sorted_implementationr!      s    
 !RZZ  66Q;!:1%qABBaDAAzz!''"4(H9ZZD9N&&qtDM;9
))A,C''.DA$?22    c                      \ rS rSrSS jrSrg)_CommonTopK%   c                    US   nUS:  a  UOU[        UR                  5      -   n[        XX45      u  pgXgR                  [        R
                  5      4$ )  Runtime for operator *TopK*.
The implementation is not the most efficient
as it sorts everything then extracts the top *k*
values.

.. warning::
    ONNX specifications may be imprecise in case of negative value
    for axis. The implementation follows what `onnxruntime`
    does in `top_k.cc
    <https://github.com/Microsoft/onnxruntime/blob/main/onnxruntime/core/providers/cpu/math/top_k.cc#L63>`_.
r   )lenr   r!   astyper   int64)selfdatainkr	   r   r   sortsortis           r    _common_run_CommonTopK._common_run&   sK     Fqyttc$**o'=0$Hll288,--r"    N)r   )__name__
__module____qualname____firstlineno__r0   __static_attributes__r2   r"   r    r$   r$   %   s    .r"   r$   c                      \ rS rSrSS jrSrg)TopK_18   Nc                .    [         R                  XU/US9$ r'   r   r$   r0   )r+   r,   r   r	   s       r    _runTopK_1._run9   s     &&tA3T&BBr"   r2   )NNr3   r4   r5   r6   r>   r7   r2   r"   r    r9   r9   8       Cr"   r9   c                      \ rS rSrSS jrSrg)TopK_10H   Nc                *    [         R                  XX#S9$ r<   r=   )r+   r,   r-   r	   s       r    r>   TopK_10._runI   s     &&t3&BBr"   r2   )Nr@   r2   r"   r    rC   rC   H   rA   r"   rC   c                  $    \ rS rSr   SS jrSrg)TopK_11X   Nc                N    US;  a  [        S5      e[        R                  XX#US9$ )a  Runtime for operator *TopK*.

The implementation is not the most efficient
as it sorts everything then extracts the top *k*
values.

.. warning::
    ONNX specifications may be imprecise in case of negative value
    for axis. The implementation follows what `onnxruntime`
    does in `top_k.cc
    <https://github.com/Microsoft/onnxruntime/blob/main/onnxruntime/core/providers/cpu/math/top_k.cc#L63>`_.
)Tr   z.TopK does not implement anything for sorted=0.)r	   r   )r   r$   r0   )r+   r,   r-   r	   r   sorteds         r    r>   TopK_11._runY   s0    ( "OPP&&t37&SSr"   r2   )NNNr@   r2   r"   r    rH   rH   X   s    
 Tr"   rH   )
__future__r   numpyr   onnx.reference.op_runr   r!   r$   r9   rC   rH   r2   r"   r    <module>rP      sK    #  '34.% .&C[ C Ck C Tk Tr"   