matmul

dragon.vm.tensorflow.linalg.matmul(
  a,
  b,
  transpose_a=False,
  transpose_b=False,
  name=None
)[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 = tf.ones((2, 3), 'float32')
b = tf.ones((3, 3), 'float32')
print(tf.linalg.matmul(a, b))

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

If inputs are transposed, remember to transpose them back:

a = tf.ones((3, 2), 'float32')
b = tf.ones((3, 3), 'float32')
print(tf.linalg.matmul(a, b))  # ``a`` takes the wrong dimensions
print(tf.linalg.matmul(a, b, transpose_a=True))  # Ok
Parameters:
  • a (dragon.Tensor) – The matrix \(a\).
  • b (dragon.Tensor) – The matrix \(b\).
  • transpose_a (bool, optional, default=False) – True to transpose \(a\) before computing.
  • transpose_b (bool, optional, default=False) – True to transpose \(b\) before computing.
  • name (str, optional) – The operation name.
Returns:

dragon.Tensor – The output tensor.