SourceForge Logo Tiny Vector Matrix library using Expression Templates Sourceforge Project Page

Introduction

This Tiny Vector and Matrix template library uses Meta Templates (MT) and Expression Templates (ET) to evaluate results at compile time -- which makes it fast for low order (tiny) systems.

"Tiny" is a subjective term, but typically means vectors and matrices of size ten (10) or less.

The technique used internally by tvmet is described by Todd Veldhuizen:

and is used by his blitz++, too. Therefore, the speed achieved by tvmet is similar to the speed of blitz++. Unfortunately, blitz++ isn't developed any more (year 2001, 2002) because of other interests being pursued by Todd Veldhuizen (like his Ph.D.). Furthermore, blitz++'s TinyVector is mainly developed for use by the blitz++ Array class -- and not for minimalistic/tiny fast math support for which tvmet is designed. Because of this, the operators and functions are incomplete or not supported well. blitz::TinyMatrix supports a few lesser operators and functions (as with blitz::TinyVector). blitz++ doesn't conform to STL (e.g. Container<>::value_type isn't defined), it defines a T_numtype or, for blitz::TinyVector, it does have an iterator begin() - but the end() is missing (blitz::TinyMatrix doesn't have anything).

These were reasons why I developed tvmet. Still, tvmet is designed to be more than a mere rehashing of blitz++. The primary design goals are:

  1. mathematical notation and correctness,
  2. high efficiency for small/tiny vector and matrices,
  3. functionality and wide range of supported operators and functions, and
  4. compatibility and portability.

The dimensions for vectors and matrices are statically bound at compile time using template arguments. The bounded dimensions feature a compile time dimension check to force adherence to proper dimensional sizes between operands (even in the night if you are sleepy). For example, you can't assign a Vector or Matrix with dimension = 3 to a Vector or Matrix of dimension = 4; nor can you create an expression using a binary operation between arguments with incompatible dimensions. This is a major difference between tvmet (which features this) and blitz++ (which does not prevent from this). Nevertheless, tvmet isn't a matlab, maple or octave for C++.

tvmet is a general purpose library and is not (yet) a linear algebra library. It does not have an interface to other numerical libraries as BLAS or LAPACK. Tiny Vector Matrix template library offers these features:

  1. Matrices and Vectors with fixed sizes (of course), the data is stored in a static array.
  2. compile time dimension check for Vectors and Matrices to preserve the mathematical meaning.
  3. vector, matrix, matrix-matrix and matrix-vector fast operations:
  4. special handling for the aliasing problem - see ... about aliasing.
  5. STL iterator interface. This opens the door to all sorts of great STL applications.
  6. type promotion (for handling Matrices and Vectors of differing types).
  7. works on self defined types such as the std::complex<> type.
  8. makes no use of exceptions. Therefore you can use it for embedded systems or in Linux kernel space.
  9. nice expression level printing for debugging purposes (print the expanded expression tree).
  10. good documentation with examples.
  11. regression tests for nearly all operations and functions.
  12. support for several compilers (see Compiler Support).
  13. written as a pure class and template library, no binary libraries and versioning are needed - designed to avoid code blot due to the use of templates.
  14. ISO/IEC 14882:1998 compliant.

Although there are many advantages and features, tvmet has some limitations. Due to the expression template and meta template programming, the compilation time increases for higher dimensional constructs. This can cause resource limitations, especially for memory (during compilation). On the other hand, the runtime performance will also decrease on higher order. Therefore only use tvmet only tiny (typically less than 10) sizes. (The maximum useful size/dimension depends on the operation, of course.) The Benchmark gives a good entry point about these problem. Other general purpose libraries and linear algebra libraries will do a better job for larger matrix/vector problems.


Author: