32 constexpr int index_from_stride_order(uint64_t stride_order,
int i) {
33 if (stride_order == 0)
return i;
34 auto stride_order_arr =
decode<R>(stride_order);
35 return stride_order_arr[i];
39 template <
int I,
int R, u
int64_t StaticExtents, std::
integral Int =
long>
40 constexpr long get_extent(std::array<Int, R>
const &shape) {
41 if constexpr (StaticExtents == 0) {
55 template <
int I, u
int64_t StaticExtents, u
int64_t Str
ideOrder,
typename F,
size_t R, std::
integral Int =
long>
56 FORCEINLINE
void for_each_static_impl(std::array<Int, R>
const &shape, std::array<long, R> &idxs, F &f) {
57 if constexpr (I == R) {
62 static constexpr int J = index_from_stride_order<R>(StrideOrder, I);
63 const long imax = get_extent<J, R, StaticExtents>(shape);
66 for (
long i = 0; i < imax; ++i) {
68 for_each_static_impl<I + 1, StaticExtents, StrideOrder>(shape, idxs, f);
94 template <u
int64_t StaticExtents, u
int64_t Str
ideOrder,
typename F, auto R, std::
integral Int =
long>
97 detail::for_each_static_impl<0, StaticExtents, StrideOrder>(shape, idxs, f);
115 template <
typename F, auto R, std::
integral Int =
long>
116 FORCEINLINE
void for_each(std::array<Int, R>
const &shape, F &&f) {
118 detail::for_each_static_impl<0, 0, 0>(shape, idxs, f);
Provides utility functions for std::array.
constexpr uint64_t static_extents(int i0, Is... is)
Encode the given shape into a single integer using the nda::encode function.
__inline__ void for_each(std::array< Int, R > const &shape, F &&f)
Loop over all possible index values of a given shape and apply a function to them.
__inline__ void for_each_static(std::array< Int, R > const &shape, F &&f)
Loop over all possible index values of a given shape and apply a function to them.
constexpr std::array< int, N > decode(uint64_t binary_representation)
Decode a uint64_t into a std::array<int, N>.
constexpr std::array< T, R > make_initialized_array(T v)
Create a new std::array object initialized with a specific value.
Provides utilities to work with permutations and to compactly encode/decode std::array objects.