shuffle_iterator#
-
template<class _IndexType = ::cuda::std::size_t, class _Bijection = random_bijection<_IndexType>>
class shuffle_iterator# shuffle_iterator
is an iterator which generates a sequence of integral values representing a random permutation.shuffle_iterator
is an iterator which generates a sequence of values representing a random permutation. This iterator is useful for working with random permutations of a range without explicitly storing them in memory. The shuffle iterator is also useful for sampling from a range by selecting only a subset of the elements in the permutation.The following code snippet demonstrates how to create a
shuffle_iterator
which generates a random permutation of the range[0, 4)#include <cuda/iterator> ... // create a shuffle_iterator cuda::shuffle_iterator iterator{cuda::random_bijection{4, cuda::std::minstd_rand(0xDEADBEEF)}}; // iterator[0] returns 1 // iterator[1] returns 3 // iterator[2] returns 2 // iterator[3] returns 0
- Template Parameters:
_IndexType – The type of the index to shuffle. Defaults to uint64_t
_BijectionFunc – The bijection to use. This should be a bijective function that maps [0..n) -> [0..n). It must be deterministic and stateless. Defaults to cuda::random_biijection<_IndexType>
Public Types
-
using iterator_category = ::cuda::std::random_access_iterator_tag#
-
using iterator_concept = ::cuda::std::random_access_iterator_tag#
-
using value_type = _IndexType#
-
using difference_type = ::cuda::std::make_signed_t<value_type>#
Public Functions
-
constexpr shuffle_iterator() noexcept = default#
- inline constexpr shuffle_iterator(
- _Bijection __bijection,
- value_type __start = 0,
Constructs a
shuffle_iterator
from a given bijection and an optional start position.- Parameters:
__bijection – The bijection representing the shuffled integer sequence
__start – The position of the iterator in the shuffled integer sequence
-
template<class _RNG>
inline explicit constexpr shuffle_iterator( - value_type __num_elements,
- _RNG &&__gen,
- value_type __start = 0,
Constructs a
shuffle_iterator
by constructing the bijection function in place and an optional start position.- Parameters:
__num_elements – The size of the bijection sequence
__gen – The random number generator to initialize the bijection
__start – The optional stating index of the
shuffle_iterator
in the bijection sequence
- inline constexpr value_type operator*(
Dereferences the
shuffle_iterator
by invoking the bijection with the stored index.
- inline constexpr value_type operator[](
- difference_type __n,
Subscripts the
shuffle_iterator
by invoking the bijection with the stored index advanced by a given number of elements.- Parameters:
__n – The additional number of elements
-
inline constexpr shuffle_iterator &operator++() noexcept#
Increments the
permutation_iterator
.
- inline constexpr shuffle_iterator operator++(
- int,
Increments the
permutation_iterator
.
-
inline constexpr shuffle_iterator &operator--() noexcept#
Decrements the
permutation_iterator
.
- inline constexpr shuffle_iterator operator--(
- int,
Decrements the
permutation_iterator
.
- inline constexpr shuffle_iterator &operator+=(
- difference_type __n,
Advances the
permutation_iterator
by a given number of elements.- Parameters:
__n – The number of elements to advance
- inline constexpr shuffle_iterator &operator-=(
- difference_type __n,
Decrements the
permutation_iterator
by a given number of elements.- Parameters:
__n – The number of elements to decrement
Friends
- inline friend constexpr shuffle_iterator operator+(
- shuffle_iterator __iter,
- difference_type __n,
Returns a copy of a
shuffle_iterator
incremented by a given number of elements.- Parameters:
__iter – The
shuffle_iterator
to copy__n – The number of elements to increment
- inline friend constexpr shuffle_iterator operator+(
- difference_type __n,
- shuffle_iterator __iter,
Returns a copy of a
shuffle_iterator
incremented by a given number of elements.- Parameters:
__n – The number of elements to increment
__iter – The
shuffle_iterator
to copy
- inline friend constexpr shuffle_iterator operator-(
- shuffle_iterator __iter,
- difference_type __n,
Returns a copy of a
shuffle_iterator
decremented by a given number of elements.- Parameters:
__iter – The
shuffle_iterator
to copy__n – The number of elements to decrement
- inline friend constexpr difference_type operator-(
- const shuffle_iterator &__x,
- const shuffle_iterator &__y,
Calculates the distance between two
shuffle_iterator
.
- inline friend constexpr bool operator==(
- const shuffle_iterator &__x,
- const shuffle_iterator &__y,
Compares two
shuffle_iterator
for equality by comparing their index.
- inline friend constexpr bool operator<(
- const shuffle_iterator &__x,
- const shuffle_iterator &__y,
Compares two
shuffle_iterator
for less than by comparing their index.
- inline friend constexpr bool operator>(
- const shuffle_iterator &__x,
- const shuffle_iterator &__y,
Compares two
shuffle_iterator
for greater than by comparing their index.
- inline friend constexpr bool operator<=(
- const shuffle_iterator &__x,
- const shuffle_iterator &__y,
Compares two
shuffle_iterator
for less equal by comparing their index.
- inline friend constexpr bool operator>=(
- const shuffle_iterator &__x,
- const shuffle_iterator &__y,
Compares two
shuffle_iterator
for greater equal by comparing their index.
-
template<class _Bijection, class _IndexType>
inline constexpr auto make_shuffle_iterator( - _Bijection __fun,
- _IndexType __start = 0,
make_shuffle_iterator creates a
shuffle_iterator
from an integer and a bijection function- Parameters:
__fun – The bijection function used for shuffling
__start – The starting position of the
shuffle_iterator