forked from mindspore-Ecosystem/mindspore
rename Tensor.tensor_scatter_* to Tensor.scatter_*
This commit is contained in:
parent
065901f416
commit
d65187f1ba
|
@ -1475,7 +1475,7 @@ mindspore.Tensor
|
|||
|
||||
Tensor。
|
||||
|
||||
.. py:method:: tensor_scatter_add(indices, updates)
|
||||
.. py:method:: scatter_add(indices, updates)
|
||||
|
||||
根据指定的更新值和输入索引,通过相加运算更新本Tensor的值。当同一索引有不同值时,更新的结果将是所有值的总和。
|
||||
|
||||
|
@ -1496,7 +1496,7 @@ mindspore.Tensor
|
|||
- **TypeError** - `indices` 的数据类型既不是int32,也不是int64。
|
||||
- **ValueError** - Tensor的shape长度小于 `indices` 的shape的最后一个维度。
|
||||
|
||||
.. py:method:: tensor_scatter_div(indices, updates)
|
||||
.. py:method:: scatter_div(indices, updates)
|
||||
|
||||
根据指定的索引, 通过除法进行计算, 将输出赋值到输出Tensor中。
|
||||
|
||||
|
@ -1518,7 +1518,7 @@ mindspore.Tensor
|
|||
- **TypeError** - `indices` 的数据类型不是int32,也不是int64。
|
||||
- **ValueError** - Tensor的shape长度小于 `indices` 的shape的最后一个维度。
|
||||
|
||||
.. py:method:: tensor_scatter_min(indices, updates)
|
||||
.. py:method:: scatter_min(indices, updates)
|
||||
|
||||
根据指定的更新值和输入索引,通过最小值运算,将结果赋值到输出Tensor中。
|
||||
|
||||
|
@ -1541,7 +1541,7 @@ mindspore.Tensor
|
|||
- **TypeError** - `indices` 的数据类型既不是int32,也不是int64。
|
||||
- **ValueError** - Tensor的shape长度小于 `indices` 的shape的最后一个维度。
|
||||
|
||||
.. py:method:: tensor_scatter_mul(indices, updates)
|
||||
.. py:method:: scatter_mul(indices, updates)
|
||||
|
||||
根据指定的索引, 通过乘法进行计算, 将输出赋值到输出Tensor中。
|
||||
|
||||
|
@ -1562,7 +1562,7 @@ mindspore.Tensor
|
|||
- **TypeError** - `indices` 的数据类型不是int32,也不是int64。
|
||||
- **ValueError** - Tensor的shape长度小于 `indices` 的shape的最后一个维度。
|
||||
|
||||
.. py:method:: tensor_scatter_sub(indices, updates)
|
||||
.. py:method:: scatter_sub(indices, updates)
|
||||
|
||||
根据指定的更新值和输入索引,通过减法进行运算,将结果赋值到输出Tensor中。当同一索引有不同值时,更新的结果将是所有值的总和。此操作几乎等同于使用 :class:`mindspore.ops.ScatterNdSub` ,只是更新后的结果是通过算子output返回,而不是直接原地更新input。
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ BuiltInTypeMap &GetMethodMap() {
|
|||
{"__lt__", prim::kPrimScalarLt}, // P.scalar_lt,
|
||||
{"__gt__", prim::kPrimScalarGt}, // P.scalar_gt,
|
||||
{"__le__", prim::kPrimScalarLe}, // P.scalar_le,
|
||||
{"__ge__", prim::kPrimScalarGe}, // P.scalar_ge,mindspore/ccsrc/pipeline/jit/resource.cc
|
||||
{"__ge__", prim::kPrimScalarGe}, // P.scalar_ge,
|
||||
{"__bool__", std::string("float_bool")}, // C.float_bool
|
||||
{"__ms_to_array__", prim::kPrimScalarToArray}, // P.scalar_to_array,
|
||||
}},
|
||||
|
@ -234,11 +234,11 @@ BuiltInTypeMap &GetMethodMap() {
|
|||
{"padding", std::string("padding")}, // padding()
|
||||
{"searchsorted", std::string("searchsorted")}, // P.Select()
|
||||
{"take", std::string("take")}, // P.GatherNd()
|
||||
{"tensor_scatter_add", std::string("tensor_scatter_add")}, // P.TensorScatterAdd()
|
||||
{"tensor_scatter_mul", std::string("tensor_scatter_mul")}, // tensor_scatter_mul()
|
||||
{"tensor_scatter_sub", std::string("tensor_scatter_sub")}, // P.TensorScatterSub()
|
||||
{"tensor_scatter_min", std::string("tensor_scatter_min")}, // P.TensorScatterMin()
|
||||
{"tensor_scatter_div", std::string("tensor_scatter_div")}, // P.TensorScatterDiv()
|
||||
{"scatter_add", std::string("tensor_scatter_add")}, // P.TensorScatterAdd()
|
||||
{"scatter_mul", std::string("tensor_scatter_mul")}, // tensor_scatter_mul()
|
||||
{"scatter_sub", std::string("tensor_scatter_sub")}, // P.TensorScatterSub()
|
||||
{"scatter_min", std::string("tensor_scatter_min")}, // P.TensorScatterMin()
|
||||
{"scatter_div", std::string("tensor_scatter_div")}, // P.TensorScatterDiv()
|
||||
{"lp_norm", std::string("lp_norm")}, // lp_norm()
|
||||
{"renorm", std::string("renorm")}, // renorm()
|
||||
{"trace", std::string("trace")}, // P.Eye()
|
||||
|
|
|
@ -756,7 +756,7 @@ class Tensor(Tensor_):
|
|||
self._init_check()
|
||||
return tensor_operator_registry.get('bitwise_xor')(self, x)
|
||||
|
||||
def tensor_scatter_mul(self, indices, updates):
|
||||
def scatter_mul(self, indices, updates):
|
||||
"""
|
||||
Creates a new tensor by multiplying the values from the positions in self tensor indicated by
|
||||
`indices`, with values from `updates`. When divided values are provided for the same
|
||||
|
@ -802,7 +802,7 @@ class Tensor(Tensor_):
|
|||
>>> # first_input_x = input_x[0][0] * updates[0] = [[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]
|
||||
>>> # 6, Perform the multiply operation for the second time:
|
||||
>>> # second_input_x = input_x[0][0] * updates[1] = [[-0.22, 0.3, 3.6], [0.4, 0.5, -3.2]]
|
||||
>>> output = input_x.tensor_scatter_mul(indices, updates)
|
||||
>>> output = input_x.scatter_mul(indices, updates)
|
||||
>>> print(output)
|
||||
[[-0.22 0.3 3.6 ]
|
||||
[ 0.4 0.5 -3.2 ]]
|
||||
|
@ -810,7 +810,7 @@ class Tensor(Tensor_):
|
|||
self._init_check()
|
||||
return tensor_operator_registry.get('tensor_scatter_mul')(self, indices, updates)
|
||||
|
||||
def tensor_scatter_div(self, indices, updates):
|
||||
def scatter_div(self, indices, updates):
|
||||
"""
|
||||
Creates a new tensor by dividing the values from the positions in self tensor indicated by
|
||||
`indices`, with values from `updates`. When divided values are provided for the same
|
||||
|
@ -850,7 +850,7 @@ class Tensor(Tensor_):
|
|||
>>> input_x = Tensor(np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]).astype('float32'))
|
||||
>>> indices = Tensor(np.array([[0, 0], [0, 0]]).astype('int32'))
|
||||
>>> updates = Tensor(np.array([1.0, 2.0]).astype('float32'))
|
||||
>>> output = input_x.tensor_scatter_div(indices, updates)
|
||||
>>> output = input_x.scatter_div(indices, updates)
|
||||
>>> print(output)
|
||||
[[-0.05, 0.3, 3.6 ]
|
||||
[ 0.4, 0.5, -3.2 ]]
|
||||
|
@ -2389,7 +2389,7 @@ class Tensor(Tensor_):
|
|||
return reduce_(self, reduce_min(keepdims), cmp_fn=minimum(), axis=axis, keepdims=keepdims,
|
||||
initial=initial, where=where)
|
||||
|
||||
def tensor_scatter_add(self, indices, updates):
|
||||
def scatter_add(self, indices, updates):
|
||||
"""
|
||||
Creates a new tensor by adding the values from the positions in self tensor indicated by
|
||||
`indices`, with values from `updates`. When multiple values are given for the same
|
||||
|
@ -2427,7 +2427,7 @@ class Tensor(Tensor_):
|
|||
>>> x = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]).astype('float32'))
|
||||
>>> indices = Tensor(np.array([[0, 0], [0, 0]]).astype('int32'))
|
||||
>>> updates = Tensor(np.array([1.0, 2.2]).astype('float32'))
|
||||
>>> output = x.tensor_scatter_add(indices, updates)
|
||||
>>> output = x.scatter_add(indices, updates)
|
||||
>>> print(output)
|
||||
[[ 3.1 0.3 3.6]
|
||||
[ 0.4 0.5 -3.2]]
|
||||
|
@ -2435,7 +2435,7 @@ class Tensor(Tensor_):
|
|||
self._init_check()
|
||||
return tensor_operator_registry.get("tensor_scatter_add")()(self, indices, updates)
|
||||
|
||||
def tensor_scatter_sub(self, indices, updates):
|
||||
def scatter_sub(self, indices, updates):
|
||||
"""
|
||||
Creates a new tensor by subtracting the values from the positions in self tensor indicated by
|
||||
`indices`, with values from `updates`. When multiple values are provided for the same
|
||||
|
@ -2473,7 +2473,7 @@ class Tensor(Tensor_):
|
|||
>>> x = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]).astype('float32'))
|
||||
>>> indices = Tensor(np.array([[0, 0], [0, 0]]).astype('int32'))
|
||||
>>> updates = Tensor(np.array([1.0, 2.2]).astype('float32'))
|
||||
>>> output = x.tensor_scatter_sub(indices, updates)
|
||||
>>> output = x.scatter_sub(indices, updates)
|
||||
>>> print(output)
|
||||
[[-3.3000002 0.3 3.6 ]
|
||||
[ 0.4 0.5 -3.2 ]]
|
||||
|
@ -2481,7 +2481,7 @@ class Tensor(Tensor_):
|
|||
self._init_check()
|
||||
return tensor_operator_registry.get('tensor_scatter_sub')()(self, indices, updates)
|
||||
|
||||
def tensor_scatter_min(self, indices, updates):
|
||||
def scatter_min(self, indices, updates):
|
||||
"""
|
||||
By comparing the value at the position indicated by `indices` in self tensor with the value in the `updates`,
|
||||
the value at the index will eventually be equal to the smallest one to create a new tensor.
|
||||
|
@ -2516,7 +2516,7 @@ class Tensor(Tensor_):
|
|||
>>> x = Tensor(np.array([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]]).astype('float32'))
|
||||
>>> indices = Tensor(np.array([[0, 0], [0, 0]]).astype('int32'))
|
||||
>>> updates = Tensor(np.array([1.0, 2.2]).astype('float32'))
|
||||
>>> output = x.tensor_scatter_min(indices, updates)
|
||||
>>> output = x.scatter_min(indices, updates)
|
||||
>>> print(output)
|
||||
[[ -0.1 0.3 3.6]
|
||||
[ 0.4 0.5 -3.2]]
|
||||
|
|
|
@ -197,9 +197,9 @@ def test_tensor_scatter_arithmetic_tensor_op(func, data_type, index_type):
|
|||
expected = tensor_scatter_np(func, input_x, indices, updates)
|
||||
|
||||
if func == 'add':
|
||||
output = input_x.tensor_scatter_add(indices, updates)
|
||||
output = input_x.scatter_add(indices, updates)
|
||||
elif func == 'sub':
|
||||
output = input_x.tensor_scatter_sub(indices, updates)
|
||||
output = input_x.scatter_sub(indices, updates)
|
||||
|
||||
np.testing.assert_allclose(output.asnumpy(), expected, rtol=1e-6)
|
||||
|
||||
|
|
|
@ -266,7 +266,7 @@ def test_tensor_scatter_arithmetic_tensor_func_check(func, data_type, index_type
|
|||
expected = tensor_scatter_np(func, input_x, indices, updates)
|
||||
|
||||
if func == 'div':
|
||||
output = input_x.tensor_scatter_div(indices, updates)
|
||||
output = input_x.scatter_div(indices, updates)
|
||||
|
||||
np.testing.assert_allclose(output.asnumpy(), expected, rtol=1e-6)
|
||||
|
||||
|
|
Loading…
Reference in New Issue