class to create an N-dimensional index range of integral indices More...
#include <taskflow/utility/iterator.hpp>
Public Types | |
| using | index_type = T |
| alias for the index type | |
Public Member Functions | |
| IndexRange ()=default | |
| constructs an N-dimensional index range without initialization | |
| template<typename... Ranges> requires (sizeof...(Ranges) == N) && (std::same_as<std::remove_cvref_t<Ranges>, IndexRange<T, 1>> && ...) | |
| IndexRange (Ranges &&... ranges) | |
| constructs an N-D index range from N 1D IndexRange<T, 1> objects | |
| IndexRange (const std::array< IndexRange< T, 1 >, N > &dims) | |
| constructs an N-D index range from an array of 1D ranges | |
| const IndexRange< T, 1 > & | dim (size_t d) const |
returns the 1D range for dimension d (read-only) | |
| IndexRange< T, 1 > & | dim (size_t d) |
returns the 1D range for dimension d (mutable) | |
| const std::array< IndexRange< T, 1 >, N > & | dims () const |
| returns the underlying array of all per-dimension 1D ranges | |
| 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 | |
| std::pair< IndexRange< T, N >, size_t > | slice_ceil (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 | |
| std::pair< IndexRange< T, N >, size_t > | slice_floor (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 | |
| 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 | |
| size_t | floor (size_t chunk_size) const |
| returns the largest hyperplane-aligned chunk size that is <= chunk_size | |
Static Public Attributes | |
| static constexpr size_t | rank = N |
| the number of dimensions | |
class to create an N-dimensional index range of integral indices
| T | the integral type of the indices |
| N | the number of dimensions (must be > 1; use IndexRange<T, 1> for 1D) |
This class represents the Cartesian product of N independent 1D index ranges, each defined by a starting index, ending index, and step size. Iteration order is row-major: the last dimension varies fastest, matching the natural nesting of C-style for-loops.
[0,0)), the active iteration space stops at that dimension. size() returns the product of all outer dimensions before the first zero, and slice_ceil / slice_floor 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:
|
default |
constructs an N-dimensional index range without initialization
The per-dimension ranges are left in an indeterminate state. Use this when the bounds will be set later via dim(d).reset().
|
inlineexplicit |
constructs an N-D index range from N 1D IndexRange<T, 1> objects
| ranges | exactly N 1D ranges, one per dimension in order from outermost (dim 0) to innermost (dim N-1) |
Each 1D range defines the begin, end, and step_size for its dimension. Dimensions are independent — any combination of positive, negative, or zero step sizes is supported, as long as each 1D range is individually valid.
|
explicit |
constructs an N-D index range from an array of 1D ranges
| dims | std::array of exactly N 1D ranges |
Equivalent to the variadic constructor but takes a pre-built array, which is useful when the ranges are constructed programmatically.
| size_t tf::IndexRange< T, N >::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
| chunk_size | hint for the desired number of flat elements |
chunk_size, or size() if chunk_size > size(), or 0 if the outermost dimension is zero-sizeAnalogous to std::ceil but operating on the discrete set of hyperplane boundary sizes of the active dimensions (those before the first zero-size dimension). Only active suffix products are considered — inactive inner dimensions do not contribute boundaries.
When chunk_size is already a natural boundary size the return equals chunk_size exactly — just like std::ceil of an integer.
|
inline |
returns the 1D range for dimension d (mutable)
| d | zero-based dimension index in [0, N) |
d Use this to update the bounds of an individual dimension at runtime, for example inside an upstream init task when using stateful ranges.
|
inline |
returns the 1D range for dimension d (read-only)
| d | zero-based dimension index in [0, N) |
d, which exposes begin(), end(), and step_size() Use this inside a for_each_by_index callable to iterate the indices assigned to each dimension of the delivered sub-box.
|
inline |
returns the underlying array of all per-dimension 1D ranges
std::array of N 1D ranges, one per dimension in order from outermost (0) to innermost (N-1)Useful when you need to inspect or iterate over all dimensions without knowing N at the call site, or when passing the full set of dimension ranges to another function.
| size_t tf::IndexRange< T, N >::floor | ( | size_t | chunk_size | ) | const |
returns the largest hyperplane-aligned chunk size that is <= chunk_size
| chunk_size | hint for the desired number of flat elements |
chunk_size, or 0 if the outermost dimension is zero-sizeAnalogous to std::floor but operating on the discrete set of hyperplane boundary sizes of the active dimensions (those before the first zero-size dimension). Only active suffix products are considered — inactive inner dimensions do not contribute boundaries.
When chunk_size is already a natural boundary size the return equals chunk_size exactly — just like std::floor of an integer, and identical to ceil in that case.
| size_t tf::IndexRange< T, N >::size | ( | ) | const |
returns the number of active flat iterations
Returns the product of dimension sizes from the outermost dimension inward, stopping before the first zero-size dimension. This matches the behaviour of sequential nested loops: a zero-size dimension prevents its own iterations and those of all deeper dimensions, but outer dimensions are unaffected.
|
inline |
returns the number of iterations along dimension d
| d | zero-based dimension index in [0, N) |
d, i.e. distance(dim(d).begin(), dim(d).end(), dim(d).step_size())This is a per-dimension count, independent of other dimensions and of the zero-size stopping rule that size() applies.
| std::pair< IndexRange< T, N >, size_t > tf::IndexRange< T, N >::slice_ceil | ( | 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
| flat_beg | starting flat index (row-major) into the active ND space |
| chunk_size | hint for the desired number of elements |
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 consumed >= 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 consumed and any overshoot is self-correcting.
| std::pair< IndexRange< T, N >, size_t > tf::IndexRange< T, N >::slice_floor | ( | 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
| flat_beg | starting flat index (row-major) into the active ND space |
| chunk_size | hint for the desired number of elements |
Analogous to std::floor: if chunk_size already aligns to a hyperplane boundary the returned box is exact (identical to slice_ceil); otherwise it rounds down to the largest box that does not exceed chunk_size, so consumed <= 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.
The trailing-zeros rule applies within the active dimensions identically to slice_ceil.
Used by static partitioners: each worker's pre-assigned flat quota is never exceeded, so workers do not double-process elements at quota boundaries.