paddle.fluid.layers.addmm(input, x, y, alpha=1.0, beta=1.0, name=None)[source]


This operator is used to perform matrix multiplication for input $x$ and $y$. $input$ is added to the final result. The equation is:

\[Out = alpha * x * y + beta * input\]

$Input$, $x$ and $y$ can carry the LoD (Level of Details) information, or not. But the output only shares the LoD information with input $input$.

  • input (Variable) – The input Tensor/LoDTensor to be added to the final result.

  • x (Variable) – The first input Tensor/LoDTensor for matrix multiplication.

  • y (Variable) – The second input Tensor/LoDTensor for matrix multiplication.

  • alpha (float) – Coefficient of $x*y$.

  • beta (float) – Coefficient of $input$.

  • name (str, optional) – Name of the output. Normally there is no need for user to set this property. For more information, please refer to Name. Default is None.


The output Tensor/LoDTensor of addmm op.

Return type



import numpy as np
import paddle
import paddle.fluid as fluid

input ='input', shape=[2, 2], dtype='float32')
x ='x', shape=[2, 2], dtype='float32')
y ='y', shape=[2, 2], dtype='float32')
out = fluid.layers.addmm( input=input, x=x, y=y, alpha=5.0, beta=0.5 )

data_x = np.ones((2, 2)).astype(np.float32)
data_y = np.ones((2, 2)).astype(np.float32)
data_input = np.ones((2, 2)).astype(np.float32)

place =  fluid.CUDAPlace(0) if fluid.core.is_compiled_with_cuda() else fluid.CPUPlace()
exe = fluid.Executor(place)
results =,
                  fetch_list=[out], feed={"input": data_input, 'x': data_x, "y": data_y})
print( np.array(results[0]) )
# [[10.5 10.5]
# [10.5 10.5]]