
On Thursday 06 December 2007, Andreas Harnack wrote:
Hi @,
shouldn't there be at least an elementary matrix class available in the standard? I notice there have been some discussions in the past, but there doesn't seem to be anything in the pipeline. So, is there any interest in a (really!) light weight statically typed matrix template class?
No, there shouldn't be. :-) The C++ landscape is littered with such things, from simpler than your example to fantastically elaborate. See <http://www.oonumerics.org/oon/> for a sample. One of the big problems is that everyone wants something slightly different. Example:
#include <algorithm> #include <functional>
template<typename T, unsigned int M, unsigned int N> class matrix { protected: T m[M][N];
OK, this makes the matrix size a compile-time decision. This is ideal for some cases and anathema for others. [...]
T& operator()(unsigned int i, unsigned int j) { return m[i][j]; } T const& operator()(unsigned int i, unsigned int j) const { return m[i][j]; }
OK, is that one-based or zero-based? Some people demand zero-based, others demand one-based. [...]
There are still a few essential but fairly basic things missing, like matrix multiplication and transposing a matrix. Elementary row operations might be useful as well for those, who want to provide complex algorithms, but that's it, basically. There shouldn't be anything in there that's more complicated than that. (Matrices are such a general concept that it can be very tricky, if not impossible, to provide any guaranties for anything above the basic stuff.)
OK, what does operator* mean? Inner product? Outer product? Direct product?
Any interest? Comments most welcome!
I'm not saying your code is wrong, it's not; it's just fine for what you want. But it's not at all fine for what the general matrix-using population wants. As an example of a library that *does* try to fill all those needs, look at Boost's very own UBlas. Flexible, has all the options covered... and IMHO rather difficult to use, and also rather slow. An an example of a library that probably does exactly what you want, but way way fast, look at 'tvmet'. My point is, I guess, that general-purpose one-size-fits-all libraries have historically been hard to use and slow; libraries that are easy to use and fast are not applicable to all uses. I personally think this issue is rather fundamental to the "computer linear algebra" problem, and nobody has yet come up with The Good Solution (not for lack of work). (BTW, I think that UBlas + template typedefs [in whatever form we get them] will grow up to be a big, strong, fast, and very useful library some day. It doesn't fit my needs at all yet, so I'm using something else). My $0.02. -- Dr. David Steffen - Software Engineer 4 Numerica Corporation (www.numerica.us <http://www.numerica.us/> )