mindspore.ops.AssignAdd

class mindspore.ops.AssignAdd[source]

Updates a Parameter by adding a value to it.

Refer to mindspore.ops.assign_add() for more details.

Inputs:
  • variable (Parameter) - The Parameter. \((N,*)\) where \(*\) means, any number of additional dimensions, its rank should be less than 8.

  • value (Union[numbers.Number, Tensor]) - The value to be added to the variable. It must have the same shape as variable if it is a Tensor.

Outputs:

Tensor, has the same data type and shape as original variable.

Supported Platforms:

Ascend GPU CPU

Examples

>>> class Net(nn.Cell):
...     def __init__(self):
...         super(Net, self).__init__()
...         self.AssignAdd = ops.AssignAdd()
...         self.variable = mindspore.Parameter(initializer(1, [1], mindspore.int64), name="global_step")
...
...     def construct(self, x):
...         self.AssignAdd(self.variable, x)
...         return self.variable
...
>>> net = Net()
>>> value = Tensor(np.ones([1]).astype(np.int64)*100)
>>> output = net(value)
>>> print(net.variable.asnumpy())
[101]