|
| | 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
|
| |
| size_t | ceil (size_t chunk_size) const |
| | returns the smallest hyperplane-aligned chunk size that is >= chunk_size, capped at size() when chunk_size exceeds the total active range size (only available when N > 1)
|
| |
| size_t | floor (size_t chunk_size) const |
| | returns the largest hyperplane-aligned chunk size that is <= chunk_size (only available when N > 1)
|
| |
| IndexRanges | upper_slice (size_t flat_beg, size_t chunk_size) const |
| | returns the smallest perfectly-aligned hyperbox reachable from flat_beg, rounding up to the next hyperplane boundary when chunk_size is not aligned (only available when N > 1)
|
| |
| IndexRanges | lower_slice (size_t flat_beg, size_t chunk_size) const |
| | returns the largest perfectly-aligned hyperbox reachable from flat_beg whose size does not exceed chunk_size, rounding down to the previous hyperplane boundary when chunk_size is not aligned (only available when N > 1)
|
| |
| IndexRanges | empty_box () const |
| | returns a box whose size() is 0 (only available when N > 1)
|
| |
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:971
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:668
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:
template<std::integral T, size_t N>
requires (N > 1)
returns the largest perfectly-aligned hyperbox reachable from flat_beg whose size does not exceed chunk_size, rounding down to the previous hyperplane boundary when chunk_size is not aligned (only available when N > 1)
- Parameters
-
| flat_beg | starting flat index (row-major) into the active ND space |
| chunk_size | hint for the desired number of elements |
- Returns
- the sub-box; its
size() gives the number of elements consumed
Analogous to std::floor: if chunk_size already aligns to a hyperplane boundary the returned box is exact (identical to upper_slice); otherwise it rounds down to the largest box that does not exceed chunk_size, so size() <= chunk_size.
Used by static partitioners: each worker's pre-assigned flat quota is never exceeded, so workers do not double-process elements at quota boundaries.
template<std::integral T, size_t N>
requires (N > 1)
returns the smallest perfectly-aligned hyperbox reachable from flat_beg, rounding up to the next hyperplane boundary when chunk_size is not aligned (only available when N > 1)
- Parameters
-
| flat_beg | starting flat index (row-major) into the active ND space |
| chunk_size | hint for the desired number of elements |
- Returns
- the sub-box; its
size() gives the number of elements consumed
Analogous to std::ceil: if chunk_size already aligns to a hyperplane boundary the returned box is exact; otherwise it rounds up to the next clean orthogonal boundary, so size() >= chunk_size.
Only the active dimensions — those before the first zero-size dimension — are partitioned. Dimensions from the first zero onward are copied into the returned box as full extent and do not affect the flat index space.
The trailing-zeros rule applies within the active dimensions: a dimension can only expand if all active dimensions inner to it start at coordinate 0. When this fires the function returns the best geometry-constrained box reachable from flat_beg.
Used by dynamic partitioners: the atomic cursor advances by the returned box's size() and any overshoot is self-correcting.