TRIQS/itertools 1.3.0
C++ range library
Loading...
Searching...
No Matches
Utilities

Detailed Description

Utilities are mostly internal implementation details and should not concern everyday users.

The only functions the might be intersting to some users are: chunk_range, make_vector_from_range and omp_chunk.

Classes

struct  itertools::iterator_facade< Iter, Value, std::forward_iterator_tag, Reference, Difference >
 CRTP base class for various iterator types in itertools. More...
 
struct  itertools::sentinel_t< Iter >
 Generic sentinel type that can be used to mark the end of a range. More...
 

Functions

std::pair< std::ptrdiff_t, std::ptrdiff_t > itertools::chunk_range (std::ptrdiff_t first, std::ptrdiff_t last, long n_chunks, long rank)
 Given an integer range [first, last), divide it as equally as possible into N chunks.
 
template<typename Iter1 , typename Iter2 >
std::iterator_traits< Iter1 >::difference_type itertools::distance (Iter1 first, Iter2 last)
 Calculate the distance between two iterators.
 
template<typename Iter >
sentinel_t< Iter > itertools::make_sentinel (Iter it)
 Create an itertools::sentinel_t from an iterator using template type deduction.
 
template<typename R >
auto itertools::make_vector_from_range (R const &rg)
 Create a vector from a range.
 
template<typename R >
auto itertools::omp_chunk (R &&rg)
 Distribute a range as evenly as possible across all OMP threads.
 

Function Documentation

◆ chunk_range()

std::pair< std::ptrdiff_t, std::ptrdiff_t > itertools::chunk_range ( std::ptrdiff_t first,
std::ptrdiff_t last,
long n_chunks,
long rank )
inlinenodiscard

#include <itertools/utils.hpp>

Given an integer range [first, last), divide it as equally as possible into N chunks.

It is intended to divide a range among different processes. If the size of the range is not divisible by N without a remainder, i.e. r = (last - first) % N, then the first r chunks have one more element.

Parameters
firstFirst value of the range.
lastLast value of the range (excluded).
n_chunksNumber of chunks to divide the range into.
rankRank of the calling process.
Returns
Pair of indices specifying the first and last (excluded) value of the chunk assigned to the calling process.

Definition at line 92 of file utils.hpp.

◆ distance()

template<typename Iter1 , typename Iter2 >
std::iterator_traits< Iter1 >::difference_type itertools::distance ( Iter1 first,
Iter2 last )
inlinenodiscard

#include <itertools/utils.hpp>

Calculate the distance between two iterators.

It is similar to std::distance, except that it can be used for two different iterator types, e.g. in case one of them is a const iterator.

Template Parameters
Iter1Iterator type #1.
Iter2Iterator type #2.
Parameters
firstIterator #1.
lastIterator #2.
Returns
Number of elements between the two iterators.

Definition at line 51 of file utils.hpp.

◆ make_sentinel()

template<typename Iter >
sentinel_t< Iter > itertools::make_sentinel ( Iter it)
nodiscard

#include <itertools/sentinel.hpp>

Create an itertools::sentinel_t from an iterator using template type deduction.

Template Parameters
IterIterator type.
Parameters
itIterator to be turned into an itertools::sentinel_t.
Returns
Sentinel object.

Definition at line 50 of file sentinel.hpp.

◆ make_vector_from_range()

template<typename R >
auto itertools::make_vector_from_range ( R const & rg)
nodiscard

#include <itertools/utils.hpp>

Create a vector from a range.

Template Parameters
RRange type.
Parameters
rgRange.
Returns
std::vector<T> containing the elements of the range, where T denotes the value type of the range.

Definition at line 69 of file utils.hpp.

◆ omp_chunk()

template<typename R >
auto itertools::omp_chunk ( R && rg)

#include <itertools/omp_chunk.hpp>

Distribute a range as evenly as possible across all OMP threads.

See chunk_range(std::ptrdiff_t, std::ptrdiff_t, long, long) and slice(R &&, std::ptrdiff_t, std::ptrdiff_t) for more details.

Template Parameters
RRange type.
Parameters
rgRange to chunk.
Returns
A itertools::sliced range, containing the chunk of the original range that belongs to the current thread.

Definition at line 40 of file omp_chunk.hpp.