addcmul

paddle.fluid.layers.addcmul(input, tensor1, tensor2, value=1.0, out=None, name=None)[source]

Calculate the element-wise multiplication of tensor1 and tensor2, then multiply the result by value, and add it to input. The shape of input, tensor1, tensor2 should be broadcastable. The equation is:

\[out = input + value * tensor1 * tensor2\]
Parameters
  • input (Variable) – The input to be added. A Tensor with type float32, float64, int32, int64.

  • tensor1 (Variable) – The tensor to be multiplied. A Tensor with type float32, float64, int32, int64.

  • tensor2 (Variable) – The tensor to be multiplied. A Tensor with type float32, float64, int32, int64.

  • value (int|float) – The multiplier for tensor1*tensor2. For float32 and float64 type input, value must be float, otherwise an integer.

  • out (Variable, Optional) – The variable that specifies the output of the operator, which can be Variable that has been created in the program. The default value is None, and a new Variable will be created to save the output. Default: None.

  • name (str, Optional) – For details, please refer to Name. Generally, no setting is required. Default: None.

Returns

The output result. A Tensor with the same data type as input’s.

Return type

out(Variable)

Examples

import paddle
import paddle.fluid as fluid
input = fluid.data(name='input', dtype='float32', shape=[3, 4])
tensor1 = fluid.data(name='tenosr1', dtype='float32', shape=[1, 4])
tensor2 = fluid.data(name='tensor2', dtype='float32', shape=[3, 4])
data = fluid.layers.addcmul(input, tensor1, tensor2, value=1.0)