I read an article about the optimisation of nested product of matrices, using dynamic programming, and I wanted to see how it is implemented in boost::uBLAS.
I'm not sure I understood the documentation (they talk about it at the very end of the page), but it seems they handle this problem. When you write R = prod(A, prod(B,C));
, the library computes A x (B x C)
or (A x B) x C
depending on the sizes of A
, B
and C
.
How can it be achieved ? How can the library "move the brackets" ? When writing such a code line, I thought the arguments of prod
would be evaluated, and then the function would be run.
The FAQ mentions the notion of expression templates. Is it linked ?
Yes, expression templates (which you may find under the name "expression trees") are involved.
Basically,
prod
doesn't return the result, but a wrapper object holding the operation (matrix multiply) and pointers to the two inputs. Ifprod
is called with such a wrapper as input, it can apply reordering optimizations.However, from my reading of that page, no such optimization is applied (it says it honors bracketing structure).