Showing posts from July, 2015

Compile Time C++ Tensors via Parameter Packs

The manipulation of tensors (n-dimensional arrays) emerges from several application domains in engineering, computer science and statistics (e.g. discrete CPDs). In C++ this is typically possible with dynamically allocated multidimensional arrays such as the ones from OpenCV (Mat class), but in many occasion there is the interest to rely on the optimizations provided by compile-size arrays.
Two approaches have been proposed: the first is based on the nesting of std::array (here) while the second, used by boost multidimensional library (here),  provides views over single fixed size array. In the latter case the size is fixed at compile-time but the multidim shape is not and there is partial compile-time size verification.

In this post I am addressing full compile-time multidimensional types obtained via C++11 template metaprogramming in particular parameter packs. A class will provide the storage of data as a flat array, and then different views can be generated over this array. In pa…