From 72fbc0111c95043b1c978a3e674877c30188fcb3 Mon Sep 17 00:00:00 2001 From: dinglinhe Date: Fri, 23 Apr 2021 11:52:51 +0800 Subject: [PATCH] Update MindSpore Doc Topk,Unique,UniqueWithPad --- mindspore/ops/operations/array_ops.py | 17 ++++++++--------- mindspore/ops/operations/math_ops.py | 2 +- mindspore/ops/operations/nn_ops.py | 11 +++++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/mindspore/ops/operations/array_ops.py b/mindspore/ops/operations/array_ops.py index eb0d5007ef..ae251d332d 100644 --- a/mindspore/ops/operations/array_ops.py +++ b/mindspore/ops/operations/array_ops.py @@ -748,11 +748,10 @@ class Unique(Primitive): Returns the unique elements of input tensor and also return a tensor containing the index of each value of input tensor corresponding to the output unique tensor. - This operation returns a tuple that contains the tensor `y` and the tensor `idx`; - where the tensor `y` contains unique elements along the `axis` of the tensor. - The sorting order of the unique elements is the same as the order that - they appear along the `axis` in `x`. Another tensor `idx` has the same size as the number of elements in `x` - along the `axis` dimension. It contains the index in the unique output `y`. + The shape of Tensor `y` and Tensor `idx` is different in most cases, because Tensor `y` will be deduplicated, + and the shape of Tensor `idx` is consistent with the input. + + To get the same shape between `idx` and `y`, please ref to 'UniqueWithPad' operator Inputs: - **x** (Tensor) - The input tensor. @@ -970,11 +969,11 @@ class UniqueWithPad(PrimitiveWithInfer): """ Returns unique elements and relative indexes in 1-D tensor, filled with padding num. - The basic function is the same as the Unique operator, but the operator adds a Pad function. - The returned tuple(`y`,`idx`) after the input tensor x is processed by the unique operator, + The basic function is the same as the Unique operator, but the UniqueWithPad operator adds a Pad function. + The returned tuple(`y`,`idx`) after the input Tensor `x` is processed by the unique operator, in which the shapes of `y` and `idx` are mostly not equal. Therefore, in order to solve the above situation, - the UniqueWithPad operator will fill the `y` tensor with the number specified by the user - to make it have the same shape as the tensor `idx`. + the UniqueWithPad operator will fill the `y` Tensor with the `pad_num` specified by the user + to make it have the same shape as the Tensor `idx`. Inputs: - **x** (Tensor) - The tensor need to be unique. Must be 1-D vector with types: int32, int64. diff --git a/mindspore/ops/operations/math_ops.py b/mindspore/ops/operations/math_ops.py index 77a65945b8..2512881305 100644 --- a/mindspore/ops/operations/math_ops.py +++ b/mindspore/ops/operations/math_ops.py @@ -1423,7 +1423,7 @@ class SquaredDifference(_MathBinaryOp): .. math:: - out_{i} = (x_{i} + y_{i}) * (x_{i} - y_{i}) = x_{i}^2 - y_{i}^2 + out_{i} = (x_{i} - y_{i}) * (x_{i} - y_{i}) = (x_{i} - y_{i})^2 Inputs: - **input_x** (Union[Tensor, Number, bool]) - The first input is a number, or a bool, diff --git a/mindspore/ops/operations/nn_ops.py b/mindspore/ops/operations/nn_ops.py index 28fb4a592a..c34d5c4bb6 100644 --- a/mindspore/ops/operations/nn_ops.py +++ b/mindspore/ops/operations/nn_ops.py @@ -2079,12 +2079,15 @@ class TopK(PrimitiveWithInfer): """ Finds values and indices of the `k` largest entries along the last dimension. - If the input is a one-dimensional Tensor, find the k largest entries in the Tensor, - and output its value and index as a Tensor. Therefore, "values [k]" is the "k" largest item in "input", - and its index is "indices [k]". + 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. Therefore, values[`k`] is the `k` largest item in `input_x`, + and its index is indices [`k`]. For a multi-dimensional matrix, - calculate the first k entries in each row (corresponding vector along the last dimension), therefore: + calculates the first `k` entries in each row (corresponding vector along the last dimension), therefore: + + .. math:: + values.shape = indices.shape = input.shape[:-1] + [k]. If the two compared elements are the same, the one with the smaller index value is returned first.