!38130 fix doc string
Merge pull request !38130 from hezhenhao1/code_docs
This commit is contained in:
commit
5dd00c5219
|
@ -364,6 +364,7 @@ Array操作
|
|||
mindspore.ops.size
|
||||
mindspore.ops.slice
|
||||
mindspore.ops.space_to_batch_nd
|
||||
mindspore.ops.sparse_segment_mean
|
||||
mindspore.ops.split
|
||||
mindspore.ops.stack
|
||||
mindspore.ops.tensor_scatter_add
|
||||
|
|
|
@ -841,9 +841,6 @@ mindspore.Tensor
|
|||
|
||||
返回一个布尔型Tensor,表示当前Tensor与 `x2` 的对应元素的差异是否在容忍度内相等。
|
||||
|
||||
.. note::
|
||||
目前,Ascend后端不支持包含 inf 或 NaN 的输入数组。因此,当输入包含NaN或inf时,结果是不确定的。在Ascend后端上, `equal_nan` 必须为真。
|
||||
|
||||
**参数:**
|
||||
|
||||
- **x2** (Tensor) - 对比的第二个输入,支持的类型有float32,float16,int32。
|
||||
|
@ -864,7 +861,6 @@ mindspore.Tensor
|
|||
- **TypeError** - 当前Tensor和 `x2` 的数据类型不同。
|
||||
- **ValueError** - 当前Tensor和 `x2` 无法广播。
|
||||
- **ValueError** - `atol` 和 `rtol` 中的任何一个小于零。
|
||||
- **ValueError** - Ascend平台上的 `equal_nan` 为False。
|
||||
|
||||
.. py:method:: item(index=None)
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
mindspore.ops.sparse_segment_mean
|
||||
=================================
|
||||
|
||||
.. py:function:: mindspore.ops.sparse_segment_mean(x, indices, segment_ids)
|
||||
|
||||
计算输出Tensor :math:`output_i = \frac{\sum_j x_{indices[j]}}{N}` ,其中平均是对所有满足 :math:`segment\_ids[j] == i` 的元素, :math:`N` 表示相加的元素个数。如果给定的分段ID :math:`i` 不存在,则有 :math:`output[i] = 0` 。
|
||||
|
||||
.. note::
|
||||
- 在CPU上, `segment_ids` 中的值会被校验是否排序,若索引值不是升序的,则抛出错误。另外, `indices` 中的值也会被校验是否在界限内,若索引值超出范围[0, x.shape[0]),则抛出错误。
|
||||
- 在GPU平台,对于 `segment_ids` 未排序和 `indices` 越界则不抛出错误。如果,无序的 `segment_ids` 会导致安全但未指定的行为,而超出范围的 `indices` 将被忽略。
|
||||
|
||||
**参数:**
|
||||
|
||||
- **x** (Tensor) - Tensor,其维度必须大于或等于1。
|
||||
- **indices** (Tensor) - 1维Tensor,数据类型为int32或int64。
|
||||
- **segment_ids** (Tensor) - 1维Tensor,与 `indices` 有同样的数据类型。索引值应当是已排序的,并且可以重复。
|
||||
|
||||
**返回:**
|
||||
|
||||
Tensor,其数据类型和维数与 `x` 相同。第一维度等于 `segment_ids` 的最后一个元素的值加一,其他维度与 `x` 的对应维度相同。
|
||||
|
||||
**异常:**
|
||||
|
||||
- **TypeError** - `x` 、 `indices` 或 `segment_ids` 不是Tensor类型。
|
||||
- **TypeError** - `x` 的数据类型不是float16、float32、float64的任一类型。
|
||||
- **TypeError** - `indices` 和 `segment_ids` 的数据类型不是float16、float32、float64的任一类型。
|
||||
- **TypeError** - `indices` 和 `segment_ids` 的数据类型不相同。
|
||||
- **ValueError** - `x` 、 `indices` 或 `segment_ids` 的维度不满足上述要求。
|
||||
- **ValueError** - `indices` 或 `segment_ids` 的shape不相同。
|
|
@ -361,6 +361,7 @@ Array Operation
|
|||
mindspore.ops.size
|
||||
mindspore.ops.slice
|
||||
mindspore.ops.space_to_batch_nd
|
||||
mindspore.ops.sparse_segment_mean
|
||||
mindspore.ops.split
|
||||
mindspore.ops.tensor_scatter_add
|
||||
mindspore.ops.tensor_scatter_min
|
||||
|
|
|
@ -1384,10 +1384,6 @@ class Tensor(Tensor_):
|
|||
"""
|
||||
Returns a boolean Tensor where two Tensors are element-wise equal within a tolerance.
|
||||
|
||||
Note:
|
||||
On Ascend, input arrays containing inf or NaN are not supported. Therefore, when the input is NaN or inf,
|
||||
the result is uncertain. And `equal_nan` must be True on Ascend.
|
||||
|
||||
Args:
|
||||
x2 (Tensor): Second Tensor to compare, with data type belongs to float32, float16, int32.
|
||||
rtol (float, optional): Relative tolerance. Default: 1e-05.
|
||||
|
@ -1405,17 +1401,16 @@ class Tensor(Tensor_):
|
|||
TypeError: If the dtype of self Tensor is not same as the `x2`.
|
||||
ValueError: If self Tensor and `x2` can not be broadcast.
|
||||
ValueError: If either of `atol` and `rtol` is less than zero.
|
||||
ValueError: If `equal_nan` is False on Ascend platform.
|
||||
|
||||
Supported Platforms:
|
||||
``Ascend`` ``CPU``
|
||||
``CPU``
|
||||
|
||||
Examples:
|
||||
>>> input = Tensor(np.array([1.3, 2.1, 3.2, 4.1, 5.1]), mindspore.float16)
|
||||
>>> other = Tensor(np.array([1.3, 3.3, 2.3, 3.1, 5.1]), mindspore.float16)
|
||||
>>> output = ops.isclose(input, other)
|
||||
>>> output = input.isclose(other)
|
||||
>>> print(output)
|
||||
[True False False False True]
|
||||
[ True False False False True]
|
||||
"""
|
||||
self._init_check()
|
||||
return tensor_operator_registry.get('isclose')(self, x2, rtol, atol, equal_nan)
|
||||
|
|
|
@ -1958,13 +1958,13 @@ def scatter_nd_max(input_x, indices, updates, use_locking=False):
|
|||
``Ascend`` ``GPU`` ``CPU``
|
||||
|
||||
Examples:
|
||||
>>> input_x = Parameter(Tensor(np.ones(8) * 10, mindspore.float32), name="x")
|
||||
>>> input_x = Parameter(Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8]), mindspore.float32), name="x")
|
||||
>>> indices = Tensor(np.array([[2], [4], [1], [7]]), mindspore.int32)
|
||||
>>> updates = Tensor(np.array([6, 7, 8, 9]), mindspore.float32)
|
||||
>>> output = ops.scatter_nd_max(input_x, indices, updates, False)
|
||||
>>> print(output)
|
||||
[ 1. 8. 6. 4. 7. 6. 7. 9.]
|
||||
>>> input_x = Parameter(Tensor(np.ones((4, 4, 4)) * 10, mindspore.int32))
|
||||
[1. 8. 6. 4. 7. 6. 7. 9.]
|
||||
>>> input_x = Parameter(Tensor(np.ones((4, 4, 4)), mindspore.int32))
|
||||
>>> indices = Tensor(np.array([[0], [2]]), mindspore.int32)
|
||||
>>> updates = Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],
|
||||
... [[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]]]), mindspore.int32)
|
||||
|
|
|
@ -2750,10 +2750,6 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
|
|||
|
||||
∣x1−x2∣ ≤ atol + rtol × ∣x2∣
|
||||
|
||||
Note:
|
||||
On Ascend, input arrays containing inf or NaN are not supported. Therefore, when the input is NaN or inf,
|
||||
the result is uncertain. And `equal_nan` must be True on Ascend.
|
||||
|
||||
Args:
|
||||
x1 (Tensor): First Tensor to compare, with data type belongs to float32, float16, int32.
|
||||
x2 (Tensor): Second Tensor to compare, with data type belongs to float32, float16, int32.
|
||||
|
@ -2772,17 +2768,16 @@ def isclose(x1, x2, rtol=1e-05, atol=1e-08, equal_nan=False):
|
|||
TypeError: If the dtype of `x1` is not same as the `x2`.
|
||||
ValueError: If `x1` and `x2` can not be broadcast.
|
||||
ValueError: If either of `atol` and `rtol` is less than zero.
|
||||
ValueError: If `equal_nan` is False on Ascend platform.
|
||||
|
||||
Supported Platforms:
|
||||
``Ascend`` ``CPU``
|
||||
``CPU``
|
||||
|
||||
Examples:
|
||||
>>> input = Tensor(np.array([1.3, 2.1, 3.2, 4.1, 5.1]), mindspore.float16)
|
||||
>>> other = Tensor(np.array([1.3, 3.3, 2.3, 3.1, 5.1]), mindspore.float16)
|
||||
>>> output = ops.isclose(input, other)
|
||||
>>> print(output)
|
||||
[True False False False True]
|
||||
[ True False False False True]
|
||||
"""
|
||||
is_close = _get_cache_prim(P.IsClose)(rtol=rtol, atol=atol, equal_nan=equal_nan)
|
||||
return is_close(x1, x2)
|
||||
|
@ -3761,8 +3756,48 @@ def cummax(x, axis):
|
|||
|
||||
|
||||
def sparse_segment_mean(x, indices, segment_ids):
|
||||
"""
|
||||
Computes the mean along sparse segments of a tensor.
|
||||
r"""
|
||||
Computes a Tensor such that :math:`output_i = \frac{\sum_j x_{indices[j]}}{N}` where mean is over :math:`j` such
|
||||
that :math:`segment\_ids[j] == i` and :math:`N` is the total number of values summed. If the mean is empty for
|
||||
a given segment ID :math:`i`, :math:`output[i] = 0`.
|
||||
|
||||
Note:
|
||||
- On CPU, values in `segment_ids` are always validated to be sorted, and an error is thrown for indices that
|
||||
are not increasing. Moreover, values in `indices` are validated to be bounded, and an error is thrown when
|
||||
`indices` are out of range[0, x.shape[0]).
|
||||
- On GPU, this does not throw an error for unsorted `segment_ids` and out-of-bound `indices`. Out-of-order
|
||||
`segment_ids` result in safe but unspecified behavior, while out-of-range `indices` will be ignored.
|
||||
|
||||
Args:
|
||||
x (Tensor): A Tensor, and its rank must be greater than or equal to 1.
|
||||
indices (Tensor): A 1-D Tensor, with int32 or int64 data type.
|
||||
segment_ids (Tensor): A 1-D Tensor, must have the same dtype as `indices`.
|
||||
Values should be sorted and can be repeated.
|
||||
|
||||
Returns:
|
||||
Tensor, whose dtype and rank is the same as `x`. The first dimension is equal to the value of the last element
|
||||
of `segment_ids` plus one, and the other dimensions are the same as those of `x`.
|
||||
|
||||
Raises:
|
||||
TypeError: If `x`, `indices` or `segment_ids` is not a Tensor.
|
||||
TypeError: If the dtype of `x` is not one of the following dtype: float16, float32, float64.
|
||||
TypeError: If the dtype of `indices` and `segment_ids` are not one of the following dtype: int32, int64.
|
||||
TypeError: If the dtype of `indices` and `segment_ids` are not the same.
|
||||
ValueError: If the shape of `x`, 'indices' or `segment_ids` don't meet the parameter description.
|
||||
ValueError: If the size of 'indices' and `segment_ids` are not the same.
|
||||
|
||||
Supported Platforms:
|
||||
``GPU`` ``CPU``
|
||||
|
||||
Examples:
|
||||
>>> x = Tensor([[0, 1, 2], [1, 2, 3], [3, 6, 7]], dtype=mindspore.float32)
|
||||
>>> indices = Tensor([0, 1, 2], dtype=mindspore.int32)
|
||||
>>> segment_ids = Tensor([1,2,2], dtype=mindspore.int32)
|
||||
>>> out = ops.sparse_segment_mean(x, indices, segment_ids)
|
||||
>>> print(out)
|
||||
[[0. 0. 0.]
|
||||
[0. 1. 2.]
|
||||
[2. 4. 5.]]
|
||||
"""
|
||||
return sparse_segment_mean_(x, indices, segment_ids)
|
||||
|
||||
|
|
|
@ -5067,7 +5067,7 @@ class ScatterNdMul(_ScatterNdOp):
|
|||
>>> indices = Tensor(np.array([[0], [2]]), mindspore.int32)
|
||||
>>> updates = Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],
|
||||
... [[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]]]), mindspore.int32)
|
||||
>>> scatter_nd_mul = ops.ScatterNdMul()
|
||||
>>> scatter_nd_mul = ScatterNdMul()
|
||||
>>> output = scatter_nd_mul(input_x, indices, updates)
|
||||
>>> print(output)
|
||||
[[[1 1 1 1]
|
||||
|
@ -5151,10 +5151,11 @@ class ScatterNdMax(_ScatterNdOp):
|
|||
``Ascend`` ``GPU`` ``CPU``
|
||||
|
||||
Examples:
|
||||
>>> from mindspore.ops.operations.array_ops import ScatterNdMax
|
||||
>>> input_x = Parameter(Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8]), mindspore.float32), name="x")
|
||||
>>> indices = Tensor(np.array([[2], [4], [1], [7]]), mindspore.int32)
|
||||
>>> updates = Tensor(np.array([6, 7, 8, 9]), mindspore.float32)
|
||||
>>> scatter_nd_max = ops.ScatterNdMax()
|
||||
>>> scatter_nd_max = ScatterNdMax()
|
||||
>>> output = scatter_nd_max(input_x, indices, updates)
|
||||
>>> print(output)
|
||||
[ 1. 8. 6. 4. 7. 6. 7. 9.]
|
||||
|
@ -5162,7 +5163,7 @@ class ScatterNdMax(_ScatterNdOp):
|
|||
>>> indices = Tensor(np.array([[0], [2]]), mindspore.int32)
|
||||
>>> updates = Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]],
|
||||
... [[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]]]), mindspore.int32)
|
||||
>>> scatter_nd_max = ops.ScatterNdMax()
|
||||
>>> scatter_nd_max = ScatterNdMax()
|
||||
>>> output = scatter_nd_max(input_x, indices, updates)
|
||||
>>> print(output)
|
||||
[[[1 1 1 1]
|
||||
|
|
|
@ -5763,11 +5763,15 @@ class IsClose(Primitive):
|
|||
``Ascend`` ``CPU``
|
||||
|
||||
Examples:
|
||||
>>> import numpy as np
|
||||
>>> from mindspore import Tensor
|
||||
>>> from mindspore.ops.operations.math_ops import IsClose
|
||||
>>> input = Tensor(np.array([1.3, 2.1, 3.2, 4.1, 5.1]), mindspore.float16)
|
||||
>>> other = Tensor(np.array([1.3, 3.3, 2.3, 3.1, 5.1]), mindspore.float16)
|
||||
>>> output = ops.IsClose()(input, other)
|
||||
>>> isclose = IsClose()
|
||||
>>> output = isclose(input, other)
|
||||
>>> print(output)
|
||||
[True False False False True]
|
||||
[ True False False False True]
|
||||
"""
|
||||
|
||||
@prim_attr_register
|
||||
|
@ -6072,35 +6076,20 @@ class Trace(Primitive):
|
|||
|
||||
class SparseSegmentMean(Primitive):
|
||||
"""
|
||||
Computes the mean along sparse segments of a tensor.
|
||||
Computes the mean along sparse segments of a Tensor.
|
||||
|
||||
Inputs:
|
||||
- **x** (Tensor) - A Tensor, and its rank must be greater equal than 1.
|
||||
- **indices** (Tensor) - A 1-D Tensor, has same rank as `segment_ids`.
|
||||
- **segment_ids** (Tensor) - A 1-D Tensor, must have the same type as `indices`.
|
||||
Values should be sorted and can be repeated.
|
||||
|
||||
Outputs:
|
||||
Tensor, with the same data type and shape as input 'x', except for dimension 0
|
||||
which is the number of segments.
|
||||
|
||||
Raises:
|
||||
TypeError: If the dtype of `x` is not one of the following dtype: float32, float64.
|
||||
TypeError: If the dtype of `indices` and `segment_ids` are not one of the following dtype: int32, int64.
|
||||
TypeError: If the dtype of `indices` and `segment_ids` are not the same.
|
||||
ValueError: If the shape of `x`, 'indices' or `segment_ids` don't meet the parameter description.
|
||||
ValueError: If the size of 'indices' and `segment_ids` are not the same.
|
||||
RuntimeError: If the value of `indices` are out of range[0, x.shape[0]).
|
||||
RuntimeError: If the value of `segment_ids` are not sorted or negative.
|
||||
Refer to :func:`mindspore.ops.sparse_segment_mean` for more detail.
|
||||
|
||||
Supported Platforms:
|
||||
``CPU``
|
||||
``GPU`` ``CPU``
|
||||
|
||||
Examples:
|
||||
>>> from mindspore import Tensor
|
||||
>>> from mindspore.ops.operations.math_ops import SparseSegmentMean
|
||||
>>> x = Tensor([[0, 1, 2], [1, 2, 3], [3, 6, 7]], dtype=mindspore.float32)
|
||||
>>> indices = Tensor([0, 1, 2], dtype=mindspore.int32)
|
||||
>>> segment_ids = Tensor([1,2,2], dtype=mindspore.int32)
|
||||
>>> sparse_segment_mean = ops.SparseSegmentMean()
|
||||
>>> sparse_segment_mean = SparseSegmentMean()
|
||||
>>> out = sparse_segment_mean(x, indices, segment_ids)
|
||||
>>> print(out)
|
||||
[[0. 0. 0.]
|
||||
|
|
Loading…
Reference in New Issue