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 per-dimension ranges | |
| size_t | size (size_t d) const |
returns the number of iterations along dimension d | |
| size_t | size () const |
| returns the total number of iterations across all dimensions | |
| std::array< T, N > | coords (size_t flat) const |
| maps a zero-based flat index to its N-D index coordinates (row-major) | |
| std::pair< IndexRange< T, N >, size_t > | consume_chunk (size_t flat_beg, size_t requested_size) const |
| consumes a linear chunk of the multidimensional space and returns the largest valid N-dimensional sub-box | |
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.
|
inlineexplicit |
constructs an N-D index range from N 1D IndexRange<T, 1> objects
| std::pair< IndexRange< T, N >, size_t > tf::IndexRange< T, N >::consume_chunk | ( | size_t | flat_beg, |
| size_t | requested_size ) const |
consumes a linear chunk of the multidimensional space and returns the largest valid N-dimensional sub-box
| flat_beg | the starting linear index (typically fetched from an atomic cursor) |
| requested_size | the maximum number of elements allowed to consume (chunk size hint) |
This function maps a linear index from a flat iteration space back into the multidimensional geometric space. To ensure the returned sub-box remains a valid, perfectly orthogonal hyper-rectangle, the function enforces a boundary constraint (the "trailing zeros" rule): a dimension can only grow if all dimensions inner to it are currently at coordinate 0.
Consequently, the actual number of elements consumed may be less than the requested_size if a geometric boundary is hit. This guarantees that workers never process discontiguous memory blocks or skip elements.
| std::array< T, N > tf::IndexRange< T, N >::coords | ( | size_t | flat | ) | const |
maps a zero-based flat index to its N-D index coordinates (row-major)
| flat | zero-based flat index in [0, size()) |
| size_t tf::IndexRange< T, N >::size | ( | ) | const |
returns the total number of iterations across all dimensions
Equivalent to the product of each dimension's element count.