OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[Docs] Extend TopK spec with NaN handling info (#33633)
Lagmator2288908a658499
diff --git a/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/sort/top-k-1.rst b/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/sort/top-k-1.rstindex 9d707471151..599608715b8 100644--- a/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/sort/top-k-1.rst+++ b/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/sort/top-k-1.rst@@ -76,6 +76,10 @@ Sorting and minimum/maximum are controlled by ``sort`` and ``mode`` attributes:If there are several elements with the same value then their output order is not determined.+**NaN Handling**++For floating-point types, the ordering of NaN values in the output is implementation-defined. Per IEEE 754, NaN fails all ordered comparisons, so there is no single correct placement for NaN in a sorted result. Different frameworks (e.g., NumPy, PyTorch) handle NaN differently, and the TopK implementation does not guarantee a specific NaN ordering. If deterministic behavior is required, NaN values should be sanitized before the TopK operation (e.g., replaced with ``-inf`` or ``+inf`` depending on the desired placement).+**Example**.. code-block:: cppdiff --git a/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/sort/top-k-11.rst b/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/sort/top-k-11.rstindex 98bdfaf216a..83e2403fb96 100644--- a/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/sort/top-k-11.rst+++ b/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/sort/top-k-11.rst@@ -94,6 +94,11 @@ Sorting and minimum/maximum are controlled by ``sort`` and ``mode`` attributes w* *sort* = ``none`` , *mode* = ``min`` - undefinedThe relative order of equivalent elements is only preserved if the ``stable`` attribute is set to ``true``. This makes the implementation use stable sorting algorithm during the computation of TopK elements. Otherwise the output order is undefined.++**NaN Handling**++For floating-point types, the ordering of NaN values in the output is implementation-defined. Per IEEE 754, NaN fails all ordered comparisons, so there is no single correct placement for NaN in a sorted result. Different frameworks (e.g., NumPy, PyTorch) handle NaN differently, and the TopK implementation does not guarantee a specific NaN ordering. If deterministic behavior is required, NaN values should be sanitized before the TopK operation (e.g., replaced with ``-inf`` or ``+inf`` depending on the desired placement).+The "by index" order means that the input tensor's elements are still sorted by value but their order in the output tensor is additionally determined by the indices of those elements in the input tensor. This might yield multiple correct results though. For example if the input tensor contains the following elements:.. code-block:: cppdiff --git a/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/sort/top-k-3.rst b/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/sort/top-k-3.rstindex 4ef7d71c91f..009fd46d4cd 100644--- a/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/sort/top-k-3.rst+++ b/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/sort/top-k-3.rst@@ -83,6 +83,10 @@ Sorting and minimum/maximum are controlled by ``sort`` and ``mode`` attributes:If there are several elements with the same value then their output order is not determined.+**NaN Handling**++For floating-point types, the ordering of NaN values in the output is implementation-defined. Per IEEE 754, NaN fails all ordered comparisons, so there is no single correct placement for NaN in a sorted result. Different frameworks (e.g., NumPy, PyTorch) handle NaN differently, and the TopK implementation does not guarantee a specific NaN ordering. If deterministic behavior is required, NaN values should be sanitized before the TopK operation (e.g., replaced with ``-inf`` or ``+inf`` depending on the desired placement).+**Example**.. code-block:: cpp