matmul¶
dragon.math.
matmul
(
inputs,
**kwargs
)[source]¶Compute the matrix multiplication.
\[\text{out} = \text{input1} \times \text{input2} \]The behavior depends on the shape of input tensors:
- If both tensors are 1d, computes the vector product.
- If tensors are 1d and >=2d, computes the vector-matrix multiplication.
- If tensors are >=2d and 1d, computes the matrix-vector multiplication.
- If both tensors are >= 2d, computes the matrix-matrix multiplication.
- If one tensor is >= 3d, applies batching and broadcasting to the computation.
Examples:
# Vector x Vector a = dragon.ones((2,), 'float32') b = dragon.ones((2,), 'float32') print(dragon.math.matmul([a, b])) # Vector x Matrix a = dragon.ones((2,), 'float32') b = dragon.ones((2, 3), 'float32') print(dragon.math.matmul([a, b])) # Matrix x Vector a = dragon.ones((3, 2), 'float32') b = dragon.ones((2,), 'float32') print(dragon.math.matmul([a, b])) # Matrix x Matrix a = dragon.ones((2, 3), 'float32') b = dragon.ones((3, 2), 'float32') print(dragon.math.matmul([a, b]))
- Parameters:
- inputs (Sequence[dragon.Tensor]) – The input tensors.
- Returns:
dragon.Tensor – The output tensor.