From d3d9e2bc742185b086e1cdd18066099b480ea868 Mon Sep 17 00:00:00 2001 From: fengyihang Date: Mon, 20 Feb 2023 17:43:11 +0800 Subject: [PATCH] fix topk param docs --- docs/api/api_python/ops/mindspore.ops.TopK.rst | 4 ++-- docs/api/api_python/ops/mindspore.ops.func_topk.rst | 4 ++-- mindspore/python/mindspore/ops/function/array_func.py | 6 ++++-- mindspore/python/mindspore/ops/operations/array_ops.py | 6 ++++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/api/api_python/ops/mindspore.ops.TopK.rst b/docs/api/api_python/ops/mindspore.ops.TopK.rst index f4ba80d0e85..6162ec3bdf8 100644 --- a/docs/api/api_python/ops/mindspore.ops.TopK.rst +++ b/docs/api/api_python/ops/mindspore.ops.TopK.rst @@ -6,7 +6,7 @@ 沿最后一个维度查找 `k` 个最大元素和对应的索引。 .. warning:: - - 如果 `sorted` 设置为False,它将使用aicpu运算符,性能可能会降低。 + - 如果 `sorted` 设置为False,它将使用aicpu运算符,性能可能会降低,另外,由于在不同平台上存在内存排布以及遍历方式不同等问题,`sorted` 设置为False时计算结果的显示顺序可能会出现不一致的情况。 如果 `input_x` 是一维Tensor,则查找Tensor中 `k` 个最大元素,并将其值和索引输出为Tensor。`values[k]` 是 `input_x` 中 `k` 个最大元素,其索引是 `indices[k]` 。 @@ -18,7 +18,7 @@ 如果两个比较的元素相同,则优先返回索引值较小的元素。 参数: - - **sorted** (bool, 可选) - 如果为True,则获取的元素将按值降序排序。如果为False,则获取的元素将按值升序排序。默认值:True。 + - **sorted** (bool, 可选) - 如果为True,则获取的元素将按值降序排序。如果为False,则不对获取的元素进行排序。默认值:True。 输入: - **input_x** (Tensor) - 需计算的输入,数据类型必须为float16、float32或int32。 diff --git a/docs/api/api_python/ops/mindspore.ops.func_topk.rst b/docs/api/api_python/ops/mindspore.ops.func_topk.rst index 9d409fddb5d..284087ca036 100644 --- a/docs/api/api_python/ops/mindspore.ops.func_topk.rst +++ b/docs/api/api_python/ops/mindspore.ops.func_topk.rst @@ -6,7 +6,7 @@ mindspore.ops.topk 沿给定维度查找 `k` 个最大或最小元素和对应的索引。 .. warning:: - - 如果 `sorted` 设置为False,它将使用aicpu运算符,性能可能会降低。 + - 如果 `sorted` 设置为False,它将使用aicpu运算符,性能可能会降低,另外,由于在不同平台上存在内存排布以及遍历方式不同等问题,`sorted` 设置为False时计算结果的显示顺序可能会出现不一致的情况。 如果 `input_x` 是一维Tensor,则查找Tensor中 `k` 个最大或最小元素,并将其值和索引输出为Tensor。`values[k]` 是 `input_x` 中 `k` 个最大元素,其索引是 `indices[k]` 。 @@ -22,7 +22,7 @@ mindspore.ops.topk - **k** (int) - 指定计算最大或最小元素的数量,必须为常量。 - **dim** (int, 可选) - 需要排序的维度。默认值:None。 - **largest** (bool, 可选) - 如果为False,则会返回前k个最小值。默认值:True。 - - **sorted** (bool, 可选) - 如果为True,则获取的元素将按值降序排序。如果为False,则获取的元素将按值升序排序。默认值:True。 + - **sorted** (bool, 可选) - 如果为True,则获取的元素将按值降序排序。如果为False,则不对获取的元素进行排序。默认值:True。 返回: 由 `values` 和 `indices` 组成的tuple。 diff --git a/mindspore/python/mindspore/ops/function/array_func.py b/mindspore/python/mindspore/ops/function/array_func.py index f61613f61c3..d345db340aa 100644 --- a/mindspore/python/mindspore/ops/function/array_func.py +++ b/mindspore/python/mindspore/ops/function/array_func.py @@ -5692,7 +5692,9 @@ def topk(input_x, k, dim=None, largest=True, sorted=True): Finds values and indices of the `k` largest or smallest entries along a given dimension. .. warning:: - - If sorted is set to False, it will use the aicpu operator, the performance may be reduced. + - If sorted is set to False, it will use the aicpu operator, the performance may be reduced. In addition, due to + different memory layout and traversal methods on different platforms, the display order of calculation results + may be inconsistent when `sorted` is False. If the `input_x` is a one-dimensional Tensor, finds the `k` largest or smallest entries in the Tensor, and outputs its value and index as a Tensor. values[`k`] is the `k` largest item in `input_x`, @@ -5713,7 +5715,7 @@ def topk(input_x, k, dim=None, largest=True, sorted=True): dim (int, optional): The dimension to sort along. Default: None. largest (bool, optional): If largest is False then the k smallest elements are returned. Default: True. sorted (bool, optional): If True, the obtained elements will be sorted by the values in descending order. - If False, the obtained elements will be sorted by the values in ascending order. Default: True. + If False, the obtained elements will not be sorted. Default: True. Returns: A tuple consisting of `values` and `indexes`. diff --git a/mindspore/python/mindspore/ops/operations/array_ops.py b/mindspore/python/mindspore/ops/operations/array_ops.py index 32a4e2dcbed..76c3da725fb 100755 --- a/mindspore/python/mindspore/ops/operations/array_ops.py +++ b/mindspore/python/mindspore/ops/operations/array_ops.py @@ -7862,7 +7862,9 @@ class TopK(Primitive): Finds values and indices of the `k` largest entries along the last dimension. .. warning:: - - If sorted is set to False, it will use the aicpu operator, the performance may be reduced. + - If sorted is set to False, it will use the aicpu operator, the performance may be reduced. In addition, due to + different memory layout and traversal methods on different platforms, the display order of calculation results + may be inconsistent when `sorted` is False. If the `input_x` is a one-dimensional Tensor, finds the `k` largest entries in the Tensor, and outputs its value and index as a Tensor. values[`k`] is the `k` largest item in `input_x`, @@ -7879,7 +7881,7 @@ class TopK(Primitive): Args: sorted (bool, optional): If True, the obtained elements will be sorted by the values in descending order. - If False, the obtained elements will be sorted by the values in ascending order. Default: True. + If False, the obtained elements will not be sorted. Default: True. Inputs: - **input_x** (Tensor) - Input to be computed, data type must be float16, float32 or int32.