
Would it be possible to have entirely abstracted matrices, ones that do not contain any numbers, just rules for their combination (multiplication etc)? For example, if we were to do: abstract_matrix<2> Z; // First template argument is number of dims, second the locations of the +1 elements. Z = 3.0*abstract_symmetric_matrix<2,0>() + 4.0*abstract_antisymmetric_matrix<2,1>(); we would end up with a matrix Z that contains just two independent values (3,4) as before but crucially also contains all the rules for its multiplication so that: double length_squared = Z*transpose(Z); is, for example, an entirely valid operation that reduces to length_squared = 3^2+4^2 and has the type of an abstract_symmetric_matrix<2,0> which is identically castable to a scalar. i think theoretically it's possible since one can compute any computable value thriugh template
on 15.08.2009 at 1:28 Edward Grace wrote : metaprogramming - why not? but i have doubts about profits of all that stuff
As another example, the previously quoted: transpose(a)*b outer product when applied to a pair of vectors of length 3 will always result in a matrix with 6 independent components (the same number of degrees of freedom that we started with). The resulting matrix (representing a 2 form) is therefore not a general matrix at all. Therefore when using that resulting matrix why should we use up 9 chunks of memory and repeat calculations when we only need to store 6 and can subsequently reduce the number of calculations. Obviously this is a trivial example, but when the matrix is NxN it can be significant. The parting shot is that if one can see through the layers of abstraction there is a real possibility for building a phenomenally efficient linear algebra library that is practically self aware! actually, if i got the point right, an implementation might do just what you wrote it doesn't hold the resulting matrix but rather an expression with some rules of computing the elements of resulting matrix
-- Pavel