mindspore.ops.addmm

View Source On Gitee
mindspore.ops.addmm(input, mat1, mat2, *, beta=1, alpha=1)[source]

Multiplies matrix mat1 and matrix mat2. The matrix input is added to the final result.

\[output = \beta input + \alpha (mat1 @ mat2)\]
Parameters
  • input (Tensor) – Tensor to be added.

  • mat1 (Tensor) – The first tensor to be multiplied.

  • mat2 (Tensor) – The second tensor to be multiplied.

Keyword Arguments
  • beta (Union[int, float], optional) – Multiplier for input. Default: 1 .

  • alpha (Union[int, float], optional) – Multiplier for mat1 @ mat2. Default: 1 .

Returns

Tensor, has the same dtype as input.

Raises

ValueError – If mat1, mat2 cannot apply matrix multiplication.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> m = np.ones((3, 3)).astype(np.float32)
>>> arr1 = np.arange(12).astype(np.float32).reshape((3, 4))
>>> arr2 = np.arange(12).astype(np.float32).reshape((4, 3))
>>> a = Tensor(arr1)
>>> b = Tensor(arr2)
>>> c = Tensor(m)
>>> output = ops.addmm(c, a, b)
>>> print(output)
[[ 43.  49.  55.]
 [115. 137. 159.]
 [187. 225. 263.]]