|
| | IndexRanges ()=default |
| | constructs an index range without initialization
|
| |
| | IndexRanges (T beg, T end, T step_size) |
| | constructs a 1D index range (only available when N == 1)
|
| |
template<typename... Ranges>
requires (sizeof...(Ranges) == N) && (std::same_as<std::decay_t<Ranges>, IndexRanges<T, 1>> && ...) |
| | IndexRanges (Ranges &&... ranges) |
| | constructs an N-D index range from N 1D ranges
|
| |
| | IndexRanges (const std::array< std::tuple< T, T, T >, N > &dims) |
| | constructs an index range from an array of (begin, end, step) tuples
|
| |
| const std::tuple< T, T, T > & | dim (size_t d) const |
| | returns the (begin, end, step) tuple for dimension d (read-only)
|
| |
| std::tuple< T, T, T > & | dim (size_t d) |
| | returns the (begin, end, step) tuple for dimension d (mutable)
|
| |
| T | begin () const |
| | queries the starting index of the range (only available when N == 1)
|
| |
| T | end () const |
| | queries the ending index of the range (only available when N == 1)
|
| |
| T | step_size () const |
| | queries the step size of the range (only available when N == 1)
|
| |
| IndexRanges & | reset (T beg, T end, T step_size) |
| | updates the range with a new starting index, ending index, and step size (only available when N == 1)
|
| |
| IndexRanges & | begin (T new_begin) |
| | updates the starting index of the range (only available when N == 1)
|
| |
| IndexRanges & | end (T new_end) |
| | updates the ending index of the range (only available when N == 1)
|
| |
| IndexRanges & | step_size (T new_step_size) |
| | updates the step size of the range (only available when N == 1)
|
| |
| IndexRanges | unravel (size_t part_beg, size_t part_end) const |
| | maps a contiguous index partition back to the corresponding subrange (only available when N == 1)
|
| |
| size_t | size (size_t d) const |
| | returns the number of iterations along dimension d
|
| |
| size_t | size () const |
| | returns the number of active flat iterations
|
| |
template<std::integral T, size_t N = 1>
class tf::IndexRanges< T, N >
class to create an N-dimensional index range of integral indices
- Template Parameters
-
| T | the integral type of the indices |
| N | the number of dimensions (defaults to 1) |
This class represents the Cartesian product of N independent 1D index ranges, each defined by a starting index, ending index, and step size. Each dimension is stored as a std::tuple<T, T, T> of (begin, end, step), accessible and mutable through dim(d).
For N == 1, the class behaves like a plain 1D range: tf::IndexRange<T> (an alias for tf::IndexRanges<T, 1>) exposes convenience accessors begin(), end(), step_size(), reset(), and unravel() directly, without going through dim(0).
for(auto i=range.begin(); i<range.end(); i+=range.step_size()) {
printf("%d ", i);
}
IndexRanges< T, 1 > IndexRange
alias for the common 1D case of tf::IndexRanges
Definition iterator.hpp:612
You can reset the range to a different value using tf::IndexRanges::reset. This is particularly useful when the range value is only known at runtime.
printf("%d ", i);
}
IndexRanges & reset(T beg, T end, T step_size)
updates the range with a new starting index, ending index, and step size (only available when N == 1)
Definition iterator.hpp:534
T end() const
queries the ending index of the range (only available when N == 1)
Definition iterator.hpp:358
T begin() const
queries the starting index of the range (only available when N == 1)
Definition iterator.hpp:346
T step_size() const
queries the step size of the range (only available when N == 1)
Definition iterator.hpp:370
- Attention
- It is the user's responsibility to ensure the given range is valid. For instance, a range from 0 to 10 with a step size of -2 is invalid.
For N > 1, iteration order is row-major: the last dimension varies fastest, matching the natural nesting of C-style for-loops.
);
printf("%zu\n", r.size());
class to create an N-dimensional index range of integral indices
Definition iterator.hpp:188
- Note
- If any dimension has zero size (e.g. an empty range such as
[0,0)), the active iteration space stops at that dimension. size() returns the product of all outer dimensions before the first zero, and upper_slice / lower_slice copy the zero-size dimension and all inner dimensions as full extent into each returned sub-box. This matches the behaviour of sequential nested loops: