MET - Matrix Expression Templates


Goals of MET

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.
 

Features

The Matrix Expression Templates library is,

Latest Release

can be downloaded here.

Installation

Makefile is prepared for GNU make and C++ compiler (gcc 2.95.2). Expand gziped tar file  and just type,

cd met/
make

Getting Started

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;
Vec<double> u(size), v(size), w(size);  // the element type is double precision.
Mat<double> m(size);                    // 3x3 square matrix

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;
 

Why expression templates?

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.
 
 

Copyright & Disclaimer

To Do

If you would like to help to develop MET, please mail to me or visit the project summary page for this project.


© 2001, Copyright by Masakatsu Ito; All Rights Reserved. mailto:masakatsu@users.sourceforge.net







This site is hosted bySourceForge Logo