mindspore.ops.baddbmm

mindspore.ops.baddbmm(x, batch1, batch2, beta=1, alpha=1)[source]

Performs a batch matrix-matrix product of matrices in batch1 and batch2. input is added to the final result. The formula is defined as follows:

\[\text{out}_{i} = \beta \text{input}_{i} + \alpha (\text{batch1}_{i} \mathbin{@} \text{batch2}_{i})\]
Parameters
  • x (Tensor) – The tensor to be added.

  • batch1 (Tensor) – The first batch of matrices to be multiplied.

  • batch2 (Tensor) – The second batch of matrices to be multiplied.

  • beta (Union[float, int], optional) – multiplier for input. The default is 1.

  • alpha (Union[float, int], optional) – multiplier for batch1 @ batch2. The default is 1.

Returns

Tensor, the output tensor.

Raises
  • TypeError – The type of x, batch1, batch2 is not Tensor.

  • TypeError – The types of x, batch1, batch2 are different.

  • TypeError – For inputs of type FloatTensor or DoubleTensor, arguments beta and alpha not be real numbers, otherwise not be integers.

  • TypeError – For Baddbmm, attributes alpha and beta are not real numbers

  • ValueError – If batch1 and batch2 are not 3-D tensors.

Supported Platforms:

Ascend GPU CPU

Examples

>>> input = Tensor(np.ones([1, 3, 3]).astype(np.float32))
>>> batch1 = Tensor(np.ones([1, 3, 4]).astype(np.float32))
>>> batch2 = Tensor(np.ones([1, 4, 3]).astype(np.float32))
>>> output = ops.baddbmm(input, batch1, batch2)
>>> print(output)
[[[5. 5. 5.]
  [5. 5. 5.]
  [5. 5. 5.]]]