romeric / Fastor

A lightweight high performance tensor algebra framework for modern C++
MIT License
745 stars 69 forks source link

How should I understood "Compile time operation minimisation such as graph optimisation, greedy matrix-chain products and nearly symbolic manipulations to reduce the complexity of evaluation of BLAS or non-BLAS type expressions by orders of magnitude" #164

Closed Realtyxxx closed 1 year ago

Realtyxxx commented 2 years ago

I'm learning the Fastor by interest, AndI want to know what is "greedy matrix-chain products "

romeric commented 1 year ago

Suppose you have

d = A * B * c

where A and B are matrices and c and d are vectors. If you multiply from left to right that is A->B->c you end up doing a matrix-matrix multiplication A*B which is costly. If you multiply from right-to-left A<-B-<c then the matrix-vector product B*c is computed first as an intermediate matrix e = B*c and finally we get d=A*e which is another matrix-vector product. So we reduce matrix-matrix multiplication to matrix-vector multiplication which is certainly faster. This is greedy-matrix chain product in a nutshell. Obviously, Fastor is capable of reducing the cost of much more complicated expressions.