mindspore.ops.ScatterNonAliasingAdd
- class mindspore.ops.ScatterNonAliasingAdd[source]
Applies sparse addition to the input using individual values or slices.
Using given values to update tensor value through the add operation, along with the input indices. This operation outputs the input_x after the update is done, which makes it convenient to use the updated value.
Inputs of input_x and updates comply with the implicit type conversion rules to make the data types consistent. If they have different data types, the lower priority data type will be converted to the relatively highest priority data type.
- Inputs:
input_x (Parameter) - The target parameter. The data type must be float16, float32 or int32.
indices (Tensor) - The index to perform the addition operation whose data type must be mindspore.int32.
updates (Tensor) - The tensor that performs the addition operation with input_x, the data type is the same as input_x, the shape is indices.shape[:-1] + x.shape[indices.shape[-1]:].
- Outputs:
Parameter, the updated input_x.
- Raises
TypeError – If dtype of indices is not int32.
TypeError – If dtype of input_x is not one of float16, float32, int32.
ValueError – If the shape of updates is not equal to indices.shape[:-1] + x.shape[indices.shape[-1]:].
RuntimeError – If the data type of input_x and updates conversion of Parameter is required when data type conversion of Parameter is not supported.
- Supported Platforms:
Ascend
Examples
>>> 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_non_aliasing_add = ops.ScatterNonAliasingAdd() >>> output = scatter_non_aliasing_add(input_x, indices, updates) >>> print(output) [ 1. 10. 9. 4. 12. 6. 7. 17.]