tensor.matmul

   fn matmul(self: @Tensor<T>, other: @Tensor<T>) -> Tensor<T>;

Performs matrix product of two tensors. The behavior depends on the dimensionality of the tensors as follows:

  • If both tensors are 1-dimensional, the dot product is returned.

  • If both arguments are 2-dimensional, the matrix-matrix product is returned.

  • If the first argument is 1-dimensional and the second argument is 2-dimensional, a 1 is prepended to its dimension for the purpose of the matrix multiply. After the matrix multiply, the prepended dimension is removed.

  • If the first argument is 2-dimensional and the second argument is 1-dimensional, the matrix-vector product is returned.

Args

  • self(@Tensor<T>) - the first tensor to be multiplied

  • other(@Tensor<T>) - the second tensor to be multiplied

Panics

  • Panics if the dimension of the tensors is higher than two.

Returns

A new Tensor<T> resulting from the matrix multiplication.

Examples

Case 1: Dot product of two vectors (1D * 1D)

Case 2: Matrix multiplication (2D * 2D)

Case 3: Matrix-Vector multiplication (2D x 1D)

Last updated

Was this helpful?