From 6bbadfcf3fe05b7f7d71352a9adff6bcf2cf7aca Mon Sep 17 00:00:00 2001 From: huangxinjing Date: Thu, 2 Feb 2023 20:38:24 +0800 Subject: [PATCH] Fix document error --- docs/api/api_python/mindspore.ops.rst | 3 ++- .../ops/mindspore.ops.func_searchsorted.rst | 21 +++++++++++++++++++ docs/api/api_python_en/mindspore.ops.rst | 3 ++- .../python/mindspore/ops/function/__init__.py | 3 ++- .../mindspore/ops/function/array_func.py | 19 ++++++++++------- 5 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 docs/api/api_python/ops/mindspore.ops.func_searchsorted.rst diff --git a/docs/api/api_python/mindspore.ops.rst b/docs/api/api_python/mindspore.ops.rst index 506fe5be3af..b3de70fa74d 100644 --- a/docs/api/api_python/mindspore.ops.rst +++ b/docs/api/api_python/mindspore.ops.rst @@ -344,9 +344,10 @@ Reduction函数 mindspore.ops.lt mindspore.ops.maximum mindspore.ops.minimum + mindspore.ops.msort mindspore.ops.ne mindspore.ops.not_equal - mindspore.ops.msort + mindspore.ops.searchsorted mindspore.ops.topk 线性代数函数 diff --git a/docs/api/api_python/ops/mindspore.ops.func_searchsorted.rst b/docs/api/api_python/ops/mindspore.ops.func_searchsorted.rst new file mode 100644 index 00000000000..456e452d6e9 --- /dev/null +++ b/docs/api/api_python/ops/mindspore.ops.func_searchsorted.rst @@ -0,0 +1,21 @@ +mindspore.ops.searchsorted +========================== + +.. py:function:: mindspore.ops.searchsorted(sorted_sequence, values, *, out_int32=False, right=False) + + 返回位置索引,根据这个索引将`values` 插入 `sorted_sequence`后,`sorted_sequence` 的最内维度的顺序保持不变。 + + 参数: + - **sorted_sequence** (Tensor) - Tensor的形状为:math:`(x_1,x_2,…,x_R-1,x_R)` 或 `x_1`。在最里面的维度上必须包含单调递增的序列。 + - **values** (Tensor) - 要插入元素的值。Tensor的形状为:math:`(x_1,x_2,…,x_R-1,x_S)`。 + + 关键字参数: + - **out_int32** (bool, 可选) - 输出数据类型。如果为True,则输出数据类型将为int32;如果为False,则输出数据类型将为int64。默认值:False。 + - **right** (bool, 可选) - 搜索策略。如果为True,则返回找到的最后一个合适的索引;如果为False,则返回第一个合适的索引。默认值:False。 + + 返回: + 表示`sorted_sequence`最内维度的索引的Tensor,如果插入`values` tensor中相应的值,则`sorted_sequence` tensor的顺序将被保留,如果out_int32为True, + 则返回的数据类型为int32,否则为int64,并且形状与values的形状相同。 + + 异常: + - **ValueError** - 如果 `sorted_sequence` 的维度不是1,并且除 `sorted_sequence` 和 `values` 的最后一个维度之外的维度不同。 diff --git a/docs/api/api_python_en/mindspore.ops.rst b/docs/api/api_python_en/mindspore.ops.rst index b24d3f5b26f..448c17adb46 100644 --- a/docs/api/api_python_en/mindspore.ops.rst +++ b/docs/api/api_python_en/mindspore.ops.rst @@ -344,9 +344,10 @@ Comparison Functions mindspore.ops.lt mindspore.ops.maximum mindspore.ops.minimum + mindspore.ops.msort mindspore.ops.ne mindspore.ops.not_equal - mindspore.ops.msort + mindspore.ops.searchsorted mindspore.ops.topk Linear Algebraic Functions diff --git a/mindspore/python/mindspore/ops/function/__init__.py b/mindspore/python/mindspore/ops/function/__init__.py index e3d5ad74ced..ce65891b571 100644 --- a/mindspore/python/mindspore/ops/function/__init__.py +++ b/mindspore/python/mindspore/ops/function/__init__.py @@ -150,7 +150,8 @@ from .array_func import ( column_stack, hstack, movedim, - moveaxis + moveaxis, + searchsorted ) from .parameter_func import ( assign, diff --git a/mindspore/python/mindspore/ops/function/array_func.py b/mindspore/python/mindspore/ops/function/array_func.py index 29ab3ae7c07..e82acf1f4b1 100644 --- a/mindspore/python/mindspore/ops/function/array_func.py +++ b/mindspore/python/mindspore/ops/function/array_func.py @@ -1219,23 +1219,25 @@ def unique_consecutive(x, return_idx=False, return_counts=False, axis=None): def searchsorted(sorted_sequence, values, *, out_int32=False, right=False): """ - Find the indices from the innermost dimension of `sorted_sequence` such that the order of the innermost dimension - within `sorted_sequence` would be preserved when the corresponding values in `values` were inserted before the - indices. + Return the position indices such that after inserting the values into the `sorted_sequence`, the order of innermost + dimension of the `sorted_sequence` remains unchanged. Args: sorted_sequence (Tensor): The shape of tensor is :math:`(x_1, x_2, ..., x_R-1, x_R)` or `(x_1)`. It must contain a monotonically increasing sequence on the innermost dimension. - values (Tensor): The shape of tensor is :math:`(x_1, x_2, ..., x_R-1, x_S)`. + values (Tensor): The value that should be inserted. + The shape of tensor is :math:`(x_1, x_2, ..., x_R-1, x_S)`. + + Keyword Args: out_int32 (bool, optional): Output datatype. If True, the output datatype will be int32; if False, the output datatype will be int64. Default: False. right (bool, optional): Search Strategy. If True, return the last suitable index found; if False, return the first such index. Default: False. Returns: - Tensor containing the indices from the innermost dimension of the input sequence such that, - if insert the corresponding value in the values tensor, the order of the tensor sequence would be preserved, - whose datatype is int32 if out_int32 is True, otherwise int64, and shape is the same as the shape of values. + Tensor containing the indices from the innermost dimension of `sorted_sequence` such that, + if insert the corresponding value in the `values` tensor, the order of `sorted_sequence` would be preserved, + whose datatype is int32 if out_int32 is True, otherwise int64, and shape is the same as the shape of `values`. Raises: ValueError: If the dimension of `sorted_sequence` isn't 1 and all dimensions except the last dimension of @@ -1247,7 +1249,7 @@ def searchsorted(sorted_sequence, values, *, out_int32=False, right=False): Examples: >>> sorted_sequence = Tensor(np.array([[0, 1, 3, 5, 7], [2, 4, 6, 8, 10]]), mindspore.float32) >>> values = Tensor(np.array([[3, 6, 9], [3, 6, 9]]), mindspore.float32) - >>> output = ops.SearchSorted()(sorted_sequence, values) + >>> output = ops.searchsorted(sorted_sequence, values) >>> print(output) [[2 4 5] [1 2 4]] @@ -6715,6 +6717,7 @@ __all__ = [ 'mvlgamma', 'swapaxes', 'swapdims', + 'searchsorted', 'argsort', 'sequence_mask', 'repeat_elements',