mindspore.mint.bmm

mindspore.mint.bmm(input, mat2)[source]

Performs batch matrix-matrix multiplication of two three-dimensional tensors.

\[\text{output}= \text{input} @ \text{mat2}\]
Parameters
  • input (Tensor) – The first batch of matrices to be multiplied. Must be a three-dimensional tensor of shape (b, n, m).

  • mat2 (Tensor) – The second batch of matrices to be multiplied. Must be a three-dimensional tensor of shape (b, m, p).

Returns

Tensor, the output tensor of shape (b, n, p), where each matrix is the product of the corresponding matrices in the input batches.

Raises
  • ValueError – If input or mat2 is not three-dimensional tensors.

  • ValueError – If the length of the third dimension of input is not equal to the length of the second dimension of mat2.

  • ValueError – If the batch size of the inputs is not equal to the batch size of the mat2.

Supported Platforms:

Ascend

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor
>>> from mindspore import mint
>>> a = Tensor(np.ones(shape=[2, 3, 4]), mindspore.float32)
>>> b = Tensor(np.ones(shape=[2, 4, 5]), mindspore.float32)
>>> output = mint.bmm(a, b)
>>> print(output)
[[[4. 4. 4. 4. 4.]
  [4. 4. 4. 4. 4.]
  [4. 4. 4. 4. 4.]]
 [[4. 4. 4. 4. 4.]
  [4. 4. 4. 4. 4.]
  [4. 4. 4. 4. 4.]]]