C++ Vector Expression Template Library

 www.partow.net  .: Home :.   .: Links :.   .: Search :.   .: Contact :. 


Description

The C++ Vector Expression Template Library is a very simple no-frills expression template library for statically typed and sized vectors. It provides basic mathematical operators and unary functions over vector types. The library incorporates delayed expression evaluation and compile time reduction semantics to approximate the optimality of vectorized expressions using hand-written loops but without the error prone and tedious manual work that is usually required.

Capabilities

The C++ Vector Expression Template Library has the following capabilities:

  • Mathematical operators (+, -, *, /)
  • Functions (min, max, sum, abs, ceil, floor, exp, log, log10, logn, root, sqrt, sqr)
  • Trigonometry (sin, cos, tan, acos, asin, atan, atan2, cosh, cot, csc, sec, sinh, tanh)
  • Equalities, Inequalities and Assignment (==, !=, <, <=, >, >=)
  • Single header implementation, no building required. No external dependencies.

The C++ Vector Expression Template Library License

Free use of the C++ Vector Expression Template Library is permitted under the guidelines and in accordance with the MIT License.

Compatibility

The C++ Vector Expression Template Library implementation is fully compatible with the following C++ compilers:

  • GNU Compiler Collection (3.5+)
  • Clang/LLVM (1.1+)
  • Microsoft Visual Studio C++ Compiler (7.1+)
  • Intel® C++ Compiler (8.x+)
  • AMD Optimizing C++ Compiler (1.2+)
  • Nvidia C++ Compiler (19.x+)
  • PGI C++ (10.x+)
  • IBM XL C/C++ (9.x+)
  • C++ Builder (XE4+)

Download

The C++ Vector Expression Template Library Download - Copyright Arash Partow The C++ Vector Expression Template Library Source Code and Examples

Simple Example

The following example evaluates an expression containing vectors, a variable and a literal and assigns said result to a corresponding vector.

int main()
{
   const std::size_t N = 6;

   typedef vxt::vector<double,N> vector_t;

   vector_t u(5.5);
   vector_t v(4.4);
   vector_t x(3.3);
   vector_t y(2.2);
   vector_t z(1.1);
   vector_t w;

   double k = 123.456;

   w = (vxt::var(k) + ((u + v) / abs(x - y)) * x) / vxt::lit(3)

   return 0;
}                    

Notes

The C++ Vector Expression Template library is based on ideas and code from the following sources:


Update 2008-03-15

A number of improvements have occurred in the C++ world since this library was initially released 5 years ago. The available compilers are much better, the new standard is beginning to take shape and as result there are many interesting libraries available that take expression templates to the next level. The following is a short list of such libraries:





© Arash Partow. All Rights Reserved.