baddbmm

paddle. baddbmm ( input: Tensor, x: Tensor, y: Tensor, beta: float = 1.0, alpha: float = 1.0, out_dtype: paddle.dtype | None = None, name: str | None = None, *, out: Tensor | None = None ) → Tensor [source]

Perform batch matrix multiplication for input \(x\) and \(y\). \(input\) is added to the final result. The equation is: .. math:

System Message: ERROR/3 (/usr/local/lib/python3.10/site-packages/paddle/base/dygraph/generated_tensor_methods_patch.py:docstring of paddle.base.dygraph.generated_tensor_methods_patch._baddbmm, line 5)

Unexpected indentation.

out = \beta \times input + \alpha \times x \times y

System Message: WARNING/2 (/usr/local/lib/python3.10/site-packages/paddle/base/dygraph/generated_tensor_methods_patch.py:docstring of paddle.base.dygraph.generated_tensor_methods_patch._baddbmm, line 1)

Literal block ends without a blank line; unexpected unindent.

where \(\beta\) and \(\alpha\) are scaling factors. :param input: The input tensor to be added to the final result. It should be a 2-D or 3-D tensor.

System Message: ERROR/3 (/usr/local/lib/python3.10/site-packages/paddle/base/dygraph/generated_tensor_methods_patch.py:docstring of paddle.base.dygraph.generated_tensor_methods_patch._baddbmm, line 8)

Unexpected indentation.

Data type should be float16, float32, float64, uint16.

System Message: WARNING/2 (/usr/local/lib/python3.10/site-packages/paddle/base/dygraph/generated_tensor_methods_patch.py:docstring of paddle.base.dygraph.generated_tensor_methods_patch._baddbmm, line 4)

Block quote ends without a blank line; unexpected unindent.

Parameters
  • x (Tensor) – The first batch of matrices to be multiplied. It should be a 3-D tensor with shape [b, n, p]. Data type should be float16, float32, float64, uint16. Alias: batch1.

  • y (Tensor) – The second batch of matrices to be multiplied. It should be a 3-D tensor with shape [b, p, m]. Data type should be float16, float32, float64, uint16. Alias: batch2.

  • beta (float, optional) – The scaling factor for input. Default: 1.0.

  • alpha (float, optional) – The scaling factor for x @ y. Default: 1.0.

  • out_dtype (paddle.dtype|None, optional) – The desired data type of the returned tensor. If None, the output tensor will have the same data type as input. Default: None.

  • name (str|None, optional) – Name for the operation (optional, default is None). For more information, please refer to api_guide_Name.

Keyword Arguments

out (Tensor, optional) – The output Tensor. If set, the result will be stored in this Tensor. Default: None.

Returns

The output tensor should be a 3-D tensor with shape [b, n, m].

Return type

Tensor

Examples

>>> import paddle

>>> x = paddle.ones([2, 2, 2])
>>> y = paddle.ones([2, 2, 2])
>>> input = paddle.ones([2, 2, 2])

>>> out = paddle.baddbmm(input=input, x=x, y=y, beta=0.5, alpha=5.0)
>>> out
Tensor(shape=[2, 2, 2], dtype=float32, place=Place(cpu), stop_gradient=True,
[[[10.50000000, 10.50000000],
  [10.50000000, 10.50000000]],
 [[10.50000000, 10.50000000],
  [10.50000000, 10.50000000]]])