Extend the intrinsic matmul
to handle more than just two matrices.
#931
Labels
idea
Proposition of an idea and opening an issue to discuss it
Motivation
The Fortran intrinisc
matmul
can handle only two matrices, i.e.result = matmul(A, B)
. While working on problems involving multiple low-rank matrices, I've been faced recently with expressions likeresult = A * B * C
, orresult = A * B * C * D
, whereA
,B
,C
andD
tend to be tall or wide matrices. Depending on how you evaluate these matrix-matrix multiplications, you can either have a pretty fast code or a terribly slow one.Except for myself, would it be of interest to anyone to extend the intrinsic
matmul
to handle expressions involving multiple matrices (say between 2 and 5, I don't think there are situations where you need much more than that). The corresponding interfaces would simply beGiven the dimensions of each array, the optimal order in which to perform the operations can be determined by solving the corresponding optimization problem using dynamic programming. Some details can be found here.
Prior Art
numpy
exposes thenumpy.linalg.multi_dot(arrays, *, out=None)
function which chains calls tonumpy.dot
using the optimal parenthesization of the matrices.I'm pretty sure
julia
has a similar feature but a quick search didn't bring actual references to itAs far as I know, Fortran does not allow for arbitrary long lists of dummy arguments (except for intrisic
max
andmin
and a couple of others I suppose). In practice, I don't think the extendedmatmul
interface would need to handle more than say 5-ish arrays though.Additional Information
Pinging @perazz, @jvdp1 and @jalvesz.
The text was updated successfully, but these errors were encountered: