28 #ifndef FTL_MAPPER_HPP
29 #define FTL_MAPPER_HPP
31 #include <nano/nano.hpp>
33 #include <type_traits>
48 template <
typename DimSizes,
typename... Indices>
52 template <
typename DimSizes,
typename IF,
typename... IR>
57 using end_index =
typename std::conditional<
58 DimSizes::size -
sizeof...(IR) == 1 ,
59 typename nano::size_t<0> ,
60 typename nano::size_t<DimSizes::size -
sizeof...(IR) - 2>>::type;
64 static constexpr
size_t dim_product_sum = nano::accumulate<DimSizes, 0, end_index::value, 1>::result;
67 static constexpr
size_t offset(
size_t current_offset, IF&& index_first, IR&&... indices_rest)
72 return DimSizes::size -
sizeof...(IR) == 1
74 std::forward<IR>(indices_rest)... )
76 std::forward<IR>(indices_rest)... );
81 template <
typename DimSizes>
85 static constexpr
size_t offset(
size_t current_offset) {
return current_offset; }
89 template <
size_t Iteration,
typename Container>
91 size_t current_offset )
93 return current_offset;
96 template <
size_t Iteration,
typename Container,
typename IF,
typename... IR>
98 size_t current_offset ,
102 size_t num_indices =
sizeof...(IR);
103 current_offset += std::accumulate(dim_sizes.begin() ,
104 dim_sizes.end() - num_indices - 1 ,
106 std::multiplies<size_t>() ) * index_first;
108 return MapToIndexDynamic<Iteration + 1>(dim_sizes, current_offset, indices_rest...);
131 template <
typename DimSizes,
typename IF,
typename... IR>
135 std::forward<IF>(index_first) ,
136 std::forward<IR>(indices_rest)... );
143 template <
typename Container,
typename IF,
typename... IR>
148 return detail::MapToIndexDynamic<1>(dim_sizes, index_first, indices_rest...);
154 #endif // FTL_MAPPER_HPP
Interface which provides static mapping (uses TMP to determine some of the mapping variables at compi...
Definition: mapper.hpp:119
size_t MapToIndexDynamic(const Container &dim_sizes, size_t current_offset)
Definition: mapper.hpp:90
static constexpr size_t offset(size_t current_offset)
Definition: mapper.hpp:85
Definition: mapper.hpp:37
Definition: mapper.hpp:141
static size_t indices_to_index(const Container &dim_sizes, IF index_first, IR...indices_rest)
Definition: mapper.hpp:144
static constexpr size_t offset(size_t current_offset, IF &&index_first, IR &&...indices_rest)
Definition: mapper.hpp:67
Takes a list of indices and a list of dimension sizes, and determines the offset of an element given ...
Definition: mapper.hpp:49
static constexpr size_t indices_to_index(IF &&index_first, IR &&...indices_rest)
Maps any number of indices which represent the location of an index in a multi-dimensional space...
Definition: mapper.hpp:132
typename std::conditional< DimSizes::size-sizeof...(IR)==1, typename nano::size_t< 0 >, typename nano::size_t< DimSizes::size-sizeof...(IR)-2 >>::type end_index
Definition: mapper.hpp:60