fn
multi_dot
→Tensormulti_dot(tensors: list[Tensor])Multiply a sequence of matrices as a single chained product.
Computes the product of a list of matrices
associating left-to-right. Optimal parenthesization can substantially reduce flops for chains with widely varying inner dimensions; the current implementation associates left-to-right (the most common case is already locally optimal).
Parameters
tensorslist of TensorSequence of at least one matrix. Inner dimensions must agree
(
tensors[i].shape[-1] == tensors[i+1].shape[-2]).Returns
TensorThe chained matrix product.
Notes
For long chains, choosing the optimal split can reduce work from (left-to-right) to a significantly smaller bound found via dynamic programming.
Examples
>>> import lucid
>>> from lucid.linalg import multi_dot
>>> A = lucid.tensor([[1.0, 2.0]])
>>> B = lucid.tensor([[3.0], [4.0]])
>>> C = lucid.tensor([[5.0]])
>>> multi_dot([A, B, C])
Tensor([[55.0000]])