aesara.tensor.matmul

Contents

aesara.tensor.matmul#

aesara.tensor.matmul(x1: ArrayLike, x2: ArrayLike, dtype: DTypeLike | None = None)[source]#

Compute the matrix product of two tensor variables.

Parameters:
  • x1 – Input arrays, scalars not allowed.

  • x2 – Input arrays, scalars not allowed.

  • dtype – The desired data-type for the array. If not given, then the type will be determined as the minimum type required to hold the objects in the sequence.

Returns:

out – The matrix product of the inputs. This is a scalar only when both x1, x2 are 1-d vectors.

Return type:

ndarray

Raises:

ValueError – If the last dimension of x1 is not the same size as the second-to-last dimension of x2. If a scalar value is passed in.

Notes

The behavior depends on the arguments in the following way.

  • If both arguments are 2-D they are multiplied like conventional matrices.

  • If either argument is N-D, N > 2, it is treated as a stack of matrices

    residing in the last two indexes and broadcast accordingly.

  • If the first argument is 1-D, it is promoted to a matrix by prepending a

    1 to its dimensions. After matrix multiplication the prepended 1 is removed.

  • If the second argument is 1-D, it is promoted to a matrix by appending a

    1 to its dimensions. After matrix multiplication the appended 1 is removed.

matmul differs from dot in two important ways:

  • Multiplication by scalars is not allowed, use mul instead.

  • Stacks of matrices are broadcast together as if the matrices were elements,

    respecting the signature (n, k), (k, m) -> (n, m):