!36006 update documents for InplaceAdd and InplaceSub
Merge pull request !36006 from zhujingxuan/code_docs_inplace_op
This commit is contained in:
commit
d27e3e7d0c
|
@ -21,4 +21,5 @@ mindspore.ops.inplace_add
|
|||
**异常:**
|
||||
|
||||
- **TypeError** - `indices` 不是int或tuple。
|
||||
- **TypeError** - `indices` 是元组,但是其中的元素不是int。
|
||||
- **TypeError** - `indices` 是元组,但是其中的元素不是int。
|
||||
- **ValueError** - `x` 的维度与 `v` 的维度不相等。
|
||||
|
|
|
@ -3,7 +3,7 @@ mindspore.ops.inplace_sub
|
|||
|
||||
.. py:function:: mindspore.ops.inplace_sub(x, v, indices)
|
||||
|
||||
根据 `indices`,将 `v` 从 `x` 中减掉。
|
||||
根据 `indices`,将 `v` 从 `x` 中减去。
|
||||
|
||||
.. note::
|
||||
`indices` 只能沿着最高轴进行索引。
|
||||
|
@ -21,4 +21,5 @@ mindspore.ops.inplace_sub
|
|||
**异常:**
|
||||
|
||||
- **TypeError** - `indices` 不是int或tuple。
|
||||
- **TypeError** - `indices` 是元组,但是其中的元素不是int。
|
||||
- **TypeError** - `indices` 是元组,但是其中的元素不是int。
|
||||
- **ValueError** - `x` 的维度与 `v` 的维度不相等。
|
||||
|
|
|
@ -824,17 +824,19 @@ def inplace_add(x, v, indices):
|
|||
Raises:
|
||||
TypeError: If `indices` is neither int nor tuple.
|
||||
TypeError: If `indices` is a tuple whose elements are not all int.
|
||||
ValueError: If length of shape of `x` is not equal to length of shape of `input_v`.
|
||||
ValueError: If the rank of `x` is not equal to the rank of `v`.
|
||||
|
||||
Supported Platforms:
|
||||
``Ascend`` ``CPU``
|
||||
|
||||
Examples:
|
||||
>>> import numpy as np
|
||||
>>> import mindspore
|
||||
>>> from mindspore import Tensor, ops
|
||||
>>> indices = (0, 1)
|
||||
>>> x = Tensor(np.array([[1, 2], [3, 4], [5, 6]]), mindspore.float32)
|
||||
>>> input_v = Tensor(np.array([[0.5, 1.0], [1.0, 1.5]]), mindspore.float32)
|
||||
>>> inplaceAdd = ops.InplaceAdd(indices)
|
||||
>>> output = inplaceAdd(x, input_v)
|
||||
>>> output = ops.inplace_add(x, input_v, indices)
|
||||
>>> print(output)
|
||||
[[1.5 3. ]
|
||||
[4. 5.5]
|
||||
|
@ -862,17 +864,19 @@ def inplace_sub(x, v, indices):
|
|||
Raises:
|
||||
TypeError: If `indices` is neither int nor tuple.
|
||||
TypeError: If `indices` is a tuple whose elements are not all int.
|
||||
ValueError: If length of shape of `x` is not equal to length of shape of `input_v`.
|
||||
ValueError: If the rank of `x` is not equal to the rank of `v`.
|
||||
|
||||
Supported Platforms:
|
||||
``Ascend`` ``CPU``
|
||||
|
||||
Examples:
|
||||
>>> import numpy as np
|
||||
>>> import mindspore
|
||||
>>> from mindspore import Tensor, ops
|
||||
>>> indices = (0, 1)
|
||||
>>> x = Tensor(np.array([[1, 2], [3, 4], [5, 6]]), mindspore.float32)
|
||||
>>> input_v = Tensor(np.array([[0.5, 1.0], [1.0, 1.5]]), mindspore.float32)
|
||||
>>> inplaceSub = ops.InplaceSub(indices)
|
||||
>>> output = inplaceSub(x, input_v)
|
||||
>>> output = ops.inplace_sub(x, input_v, indices)
|
||||
>>> print(output)
|
||||
[[0.5 1. ]
|
||||
[2. 2.5]
|
||||
|
@ -3251,6 +3255,7 @@ def rad2deg(x):
|
|||
out = x * 180.0 / math.pi
|
||||
return out
|
||||
|
||||
|
||||
#####################################
|
||||
# Reduction Operation Functions.
|
||||
#####################################
|
||||
|
|
|
@ -1773,28 +1773,12 @@ class InplaceAdd(PrimitiveWithInfer):
|
|||
"""
|
||||
Adds `v` into specified rows of `x`. Computes `y` = `x`; y[i,] += `v`.
|
||||
|
||||
Args:
|
||||
indices (Union[int, tuple]): Indices into the left-most dimension of `x`, and determines which rows of `x`
|
||||
to add with `v`. It is an integer or a tuple, whose value is in [0, the first dimension size of `x`).
|
||||
|
||||
Inputs:
|
||||
- **x** (Tensor) - The first input is a tensor whose data type is float16, float32 or int32.
|
||||
:math:`(N,*)` where :math:`*` means, any number of additional dimensions, its rank should be less than 8.
|
||||
- **input_v** (Tensor) - The second input is a tensor that has the same dimension sizes as `x` except
|
||||
the first dimension, which must be the same as indices' size. It has the same data type with `x`.
|
||||
|
||||
Outputs:
|
||||
Tensor, has the same shape and dtype as `x`.
|
||||
|
||||
Raises:
|
||||
TypeError: If `indices` is neither int nor tuple.
|
||||
TypeError: If `indices` is a tuple whose elements are not all int.
|
||||
ValueError: If length of shape of `x` is not equal to length of shape of `input_v`.
|
||||
|
||||
Supported Platforms:
|
||||
``Ascend`` ``CPU``
|
||||
Refer to :func:`mindspore.ops.inplace_add` for more detail.
|
||||
|
||||
Examples:
|
||||
>>> import numpy as np
|
||||
>>> import mindspore
|
||||
>>> from mindspore import Tensor, ops
|
||||
>>> indices = (0, 1)
|
||||
>>> x = Tensor(np.array([[1, 2], [3, 4], [5, 6]]), mindspore.float32)
|
||||
>>> input_v = Tensor(np.array([[0.5, 1.0], [1.0, 1.5]]), mindspore.float32)
|
||||
|
@ -1842,28 +1826,12 @@ class InplaceSub(PrimitiveWithInfer):
|
|||
"""
|
||||
Subtracts `v` into specified rows of `x`. Computes `y` = `x`; y[i,] -= `v`.
|
||||
|
||||
Args:
|
||||
indices (Union[int, tuple]): Indices into the left-most dimension of `x`, and determines which rows of `x`
|
||||
to subtract with `v`. It is an int or tuple, whose value is in [0, the first dimension size of `x`).
|
||||
|
||||
Inputs:
|
||||
- **x** (Tensor) - The first input is a tensor whose data type is float16, float32 or int32.
|
||||
:math:`(N,*)` where :math:`*` means, any number of additional dimensions, its rank should be less than 8.
|
||||
- **input_v** (Tensor) - The second input is a tensor who has the same dimension sizes as `x` except
|
||||
the first dimension, which must be the same as indices' size. It has the same data type with `x`.
|
||||
|
||||
Outputs:
|
||||
Tensor, has the same shape and dtype as `x`.
|
||||
|
||||
Raises:
|
||||
TypeError: If `indices` is neither int nor tuple.
|
||||
TypeError: If `indices` is a tuple whose elements are not all int.
|
||||
ValueError: If length of shape of `x` is not equal to length of shape of `input_v`.
|
||||
|
||||
Supported Platforms:
|
||||
``Ascend`` ``CPU``
|
||||
Refer to :func:`mindspore.ops.inplace_sub` for more detail.
|
||||
|
||||
Examples:
|
||||
>>> import numpy as np
|
||||
>>> import mindspore
|
||||
>>> from mindspore import Tensor, ops
|
||||
>>> indices = (0, 1)
|
||||
>>> x = Tensor(np.array([[1, 2], [3, 4], [5, 6]]), mindspore.float32)
|
||||
>>> input_v = Tensor(np.array([[0.5, 1.0], [1.0, 1.5]]), mindspore.float32)
|
||||
|
|
Loading…
Reference in New Issue