matmul

dragon.math.matmul(
  inputs,
  transpose_a=False,
  transpose_b=False,
  **kwargs
)[source]

Compute the matrix multiplication.

\[y = a \times b \]

The rank of a and b should be equal and >= 2:

# Ok, a typical matrix multiplication
a = dragon.ones((2, 3), 'float32')
b = dragon.ones((3, 3), 'float32')
print(dragon.math.matmul([a, b]))

# Compute a batch matrix multiplication if rank > 2
aa = dragon.ones((4, 2, 3), 'float32')
bb = dragon.ones((4, 3, 3), 'float32')
print(dragon.math.matmul([aa, bb]))

If inputs are transposed, remember to transpose them back:

a = dragon.ones((3, 2), 'float32')
b = dragon.ones((3, 3), 'float32')
print(dragon.math.matmul([a, b]))  # ``a`` takes the wrong dimensions
print(dragon.math.matmul([a, b], transpose_a=True))  # Ok
Parameters:
  • inputs (Sequence[dragon.Tensor]) – The matrix \(a\) and \(b\).
  • transpose_a (bool, optional, default=False) – True to transpose \(a\) before computation.
  • transpose_b (bool, optional, default=False) – True to transpose \(b\) before computation.
Returns:

dragon.Tensor – The output tensor.