C++ matrix and vector libraries make the scientific/engineering programming easier than legacy Fortran. Overloaded operators allow to write linear algebraic expressions as what you see in a text book like u = m*v + w in C++, instead of boring loops in fortran or C. This advantage, however, came with a performance penalty until recently. Due to the overhead of temporaries and copying of matrix objects, C++ lagged behind fortran's performance by an order of magnitude.A technique called expression templates is a way to make C++ codes faster but keep the advantages of object-oriented programming. Unfortunately, I have not found any ordinary matrix library with that technique implemented, though its effectiveness was already proved in various array libraries, Blitz++,POOMA, PETE. That is why I decided to make MET open-source.
The Matrix Expression Templates library is,
can be downloaded here.
Makefile is prepared for GNU make and C++ compiler (gcc 2.95.2). Expand gziped tar file and just type,cd met/
make
Let's start with a simple example. Consider u = m*v + w, where u,v and w are vectors and m is matrix.const int size = 3;
v(0) = 1; v(1) = 3; v(2) = 5;
// access to the vector element
w = v;
m(0,0) = 2; m(0,1) = 3; m(0,2) = 4; // access
to the matrix element
// set the rest of elements as you like.
u = m * v + w;
cout << "Answer is (";
for (int i=0; i<size; i++) cout << " " << u(i);
cout << " ) ." << endl;
A native implementation would introduce temporary vectors for m*v and m*v + w and copies the result of m*v and m*v + w . But a smart library with expression templates introduce no temporaries, copies no objects, and touches each element of the matrix the minimum number of times.Detailed explanation of the technique and the outstanding results that C++ can rival to Fortan are shown in Blitz++ web site.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
If you would like to help to develop MET, please mail to me or visit the project summary page for this project.
- Add the interfaces to LAPACK library.
© 2001, Copyright by Masakatsu Ito; All Rights Reserved. mailto:masakatsu@users.sourceforge.net