Skip to main content
Log in

Mojo function

matmul

matmul(lhs: Symbol, rhs: Symbol, location: Optional[_SourceLocation] = Optional(None)) -> Symbol

Computes the matrix multiplication of two symbolic tensors.

Performs general matrix multiplication with broadcasting.

If the lhs is 1d, it will be reshaped to 1xD. If the rhs is 1d, it will be reshaped to Dx1. In both cases, the addition 1 dimensions will be removed from the output shape.

For the multiplication, the innermost (rightmost) 2 dimensions are treated as a maxtrix. The lhs matrix will have the shape MxK. The rhs matrix will have the shape KxN. The output will have the shape MxN The K dimensions must be equivalent in both matrices.

The remaining outer dimensions will be broadcasted.

Args:

  • lhs (Symbol): The left-hand-side of the matmul.
  • rhs (Symbol): The right-hand-side of the matmul.
  • location (Optional[_SourceLocation]): An optional location for a more specific error message.

Returns:

A symbolic tensor representing he result of broadcasting the two matricies together and then performing a matrix multiply along the innermost two dimension of each tensor.