Burn Core: burn::tensor::Tensor::matmul

Burn Core: burn::tensor::Tensor::matmul

The Tensor::matmul method performs matrix multiplication between two compatible tensors. The left-hand tensor supplies the row dimension, and the right-hand tensor supplies the output column dimension. For rank-2 tensors, the inner dimensions must match.

The returned tensor has the resulting matrix shape [m, n] for standard two-dimensional multiplication. In model code, this operation is commonly used inside dense layers, attention projections, and linear transformations.

Parameters

Parameter Name Type Description
self Tensor<B, 2> The left-hand matrix tensor with shape [m, k].
other Tensor<B, 2> The right-hand matrix tensor with shape [k, n].
let device = B::Device::default();
let a = Tensor::<B, 2>::ones([2, 3], &device);
let b = Tensor::<B, 2>::ones([3, 4], &device);
let y = a.matmul(b);

Example Output

{
  "status": "success",
  "operation": "matmul",
  "input_shape": [2, 3],
  "rhs_shape": [3, 4],
  "output_shape": [2, 4]
}

Used In Technical Article

Rust Burn Tensor Manipulation and Gradient Tracking

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top