Blitz++
The Blitz++ project brings high-performance numerical computing to C++. In some
respects, it is what valarray<>
should have been. Blitz++ has powerful array and matrix
classes, operators, and functions, with strides, subarrays, and so on.
The package is written to minimize the number of unnecessary temporary
objects and take advantage of compile-time computation (via template
metaprogramming) whenever possible.
One of the key optimizations is that arithmetic operators and mathematical functions involving Blitz++ arrays do not compute values immediately. Instead, they return expression objects. When an expression object is assigned to an array, the expression is computed, storing the results directly in the target of the assignment, without the need for large temporary arrays.
Example B-1 shows a program that demonstrates a few of the features of Blitz++.
#include <iostream> #include <ostream> #include "blitz/array.h" // Blitz formats output in a manner that is best suited for subsequent input by a // program, not for reading by a human. The print( ) function uses a format that // is slightly better for human readers. (Further improvement is left as an // exercise.) template<typename T> void print(const blitz::Array<T, 3>& a) { std::cout << a.extent(0) << " x " << a.extent(1) << " x " << a.extent(2) << ":\n["; for (size_t i = a.lbound(0); i <= a.ubound(0); ++i) { // Blitz can print a 2-D array well enough, so extract each 2-D plane and // ...