mindspore.Tensor.addmm

Tensor.addmm(mat1, mat2, *, beta=1, alpha=1) Tensor

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

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

Warning

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

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

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

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 self and the same shape as mat1 @ mat2.

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

  • TypeError – If the types of self, 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 =  input.(mat1, mat2)
>>> print(output)
[[5. 5. 5.]
 [5. 5. 5.]
 [5. 5. 5.]]