45 constexpr int index_from_stride_order(uint64_t stride_order,
int i) {
46 if (stride_order == 0)
return i;
47 auto stride_order_arr =
decode<R>(stride_order);
48 return stride_order_arr[i];
52 template <
int I,
int R, u
int64_t StaticExtents, std::
integral Int =
long>
53 constexpr long get_extent(std::array<Int, R>
const &shape) {
54 if constexpr (StaticExtents == 0) {
68 template <
int I, u
int64_t StaticExtents, u
int64_t Str
ideOrder,
typename F,
size_t R, std::
integral Int =
long>
69 FORCEINLINE
void for_each_static_impl(std::array<Int, R>
const &shape, std::array<long, R> &idxs, F &f) {
70 if constexpr (I == R) {
75 static constexpr int J = index_from_stride_order<R>(StrideOrder, I);
76 const long imax = get_extent<J, R, StaticExtents>(shape);
79 for (
long i = 0; i < imax; ++i) {
81 for_each_static_impl<I + 1, StaticExtents, StrideOrder>(shape, idxs, f);
107 template <u
int64_t StaticExtents, u
int64_t Str
ideOrder,
typename F, auto R, std::
integral Int =
long>
110 detail::for_each_static_impl<0, StaticExtents, StrideOrder>(shape, idxs, f);
128 template <
typename F, auto R, std::
integral Int =
long>
129 FORCEINLINE
void for_each(std::array<Int, R>
const &shape, F &&f) {
131 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.