mindspore.mint.addmm

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

Performs a matrix multiplication of the 2-D matrices mat1 and mat2. The matrix input is added to the final result. The formula is defined as follows:

\[output = \beta input + \alpha (mat1 @ mat2)\]

Warning

This is an experimental API that is subject to change or deletion.

Parameters
  • input (Tensor) – matrix to be added, the shape must be broadcastable with mat1 @ mat2.

  • mat1 (Tensor) – the first matrix to be matrix multiplied, must be 2-D Tensor, with the same shape of the input.

  • mat2 (Tensor) – the second matrix to be matrix multiplied, must be 2-D Tensor, with the same shape of the input.

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

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

Returns

Tensor, with the same dtype as input and the same shape as mat1 @ mat2.

Raises
  • TypeError – If the type of input, mat1 or mat2 is not Tensor.

  • TypeError – If the types of input, mat1, mat2 are different.

  • ValueError – If mat1 and mat2 are not 2-D tensors.

Supported Platforms:

Ascend

Examples

>>> import numpy as np
>>> from mindspore import Tensor, mint
>>> input = Tensor(np.ones([3, 3]).astype(np.float32))
>>> mat1 = Tensor(np.ones([3, 4]).astype(np.float32))
>>> mat2 = Tensor(np.ones([4, 3]).astype(np.float32))
>>> output =  mint.addmm(input, mat1, mat2)
>>> print(output)
[[5. 5. 5.]
 [5. 5. 5.]
 [5. 5. 5.]]