Implements the linearization of a multidimensional id to a scalar. More...
Public Member Functions | |
template<typename Index , typename Size > | |
std::pair< typename tuple_element< 0, Index >::type, typename tuple_element< 0, Size >::type > | operator() (Index const &id, Size const &size) |
Implements the linearization of a multidimensional id to a scalar.
The linearization is the sum of the products of each element of the index and all lower-dimension elements of the size. For example, index (2,0,1) given size (4, 2, 3) would linearize to 2*3*2 + 0*3 + 1 = 13.
Two template parameters are used to allow the linearization to be performed in a linear number of instances. The instantiations traverse down to the innermost dimension, and then in the returns construct the product and sum on the fly. This struct is used in all but the first and last instance.