Shuffling

template <typename DerivedPolicy,   typename RandomIterator,   typename URBG> _CCCL_HOST_DEVICE void shuffle(const thrust::detail::execution_policy_base< DerivedPolicy > & exec,   RandomIterator first,   RandomIterator last,   URBG && g);
template <typename RandomIterator,   typename URBG> _CCCL_HOST_DEVICE void shuffle(RandomIterator first,   RandomIterator last,   URBG && g);
template <typename DerivedPolicy,   typename RandomIterator,   typename OutputIterator,   typename URBG> _CCCL_HOST_DEVICE void shuffle_copy(const thrust::detail::execution_policy_base< DerivedPolicy > & exec,   RandomIterator first,   RandomIterator last,   OutputIterator result,   URBG && g);
template <typename RandomIterator,   typename OutputIterator,   typename URBG> _CCCL_HOST_DEVICE void shuffle_copy(RandomIterator first,   RandomIterator last,   OutputIterator result,   URBG && g);

Functions

Function shuffle

template <typename DerivedPolicy,   typename RandomIterator,   typename URBG> _CCCL_HOST_DEVICE void shuffle(const thrust::detail::execution_policy_base< DerivedPolicy > & exec,   RandomIterator first,   RandomIterator last,   URBG && g); shuffle reorders the elements [first, last) by a uniform pseudorandom permutation, defined by random engine g.

The algorithm’s execution is parallelized as determined by exec.

The following code snippet demonstrates how to use shuffle to create a random permutation using the thrust::host execution policy for parallelization:

#include <thrust/shuffle.h>
#include <thrust/random.h>
#include <thrust/execution_policy.h>
int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
const int N = sizeof(A)/sizeof(int);
thrust::default_random_engine g;
thrust::shuffle(thrust::host, A, A + N, g);
// A is now {6, 5, 8, 7, 2, 1, 4, 3, 10, 9}

Template Parameters:

  • DerivedPolicy The name of the derived execution policy.
  • RandomIterator is a random access iterator
  • URBG is a uniform random bit generator

Function Parameters:

  • exec The execution policy to use for parallelization.
  • first The beginning of the sequence to shuffle.
  • last The end of the sequence to shuffle.
  • g A UniformRandomBitGenerator

See: shuffle_copy

Function shuffle

template <typename RandomIterator,   typename URBG> _CCCL_HOST_DEVICE void shuffle(RandomIterator first,   RandomIterator last,   URBG && g); shuffle reorders the elements [first, last) by a uniform pseudorandom permutation, defined by random engine g.

The following code snippet demonstrates how to use shuffle to create a random permutation.

#include <thrust/shuffle.h>
#include <thrust/random.h>
int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
const int N = sizeof(A)/sizeof(int);
thrust::default_random_engine g;
thrust::shuffle(A, A + N, g);
// A is now {6, 5, 8, 7, 2, 1, 4, 3, 10, 9}

Template Parameters:

  • RandomIterator is a random access iterator
  • URBG is a uniform random bit generator

Function Parameters:

  • first The beginning of the sequence to shuffle.
  • last The end of the sequence to shuffle.
  • g A UniformRandomBitGenerator

See: shuffle_copy

Function shuffle_copy

template <typename DerivedPolicy,   typename RandomIterator,   typename OutputIterator,   typename URBG> _CCCL_HOST_DEVICE void shuffle_copy(const thrust::detail::execution_policy_base< DerivedPolicy > & exec,   RandomIterator first,   RandomIterator last,   OutputIterator result,   URBG && g); shuffle_copy differs from shuffle only in that the reordered sequence is written to different output sequences, rather than in place. shuffle_copy reorders the elements [first, last) by a uniform pseudorandom permutation, defined by random engine g.

The algorithm’s execution is parallelized as determined by exec.

The following code snippet demonstrates how to use shuffle_copy to create a random permutation.

#include <thrust/shuffle.h>
#include <thrust/random.h>
#include <thrust/execution_policy.h>
int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int result[10];
const int N = sizeof(A)/sizeof(int);
thrust::default_random_engine g;
thrust::shuffle_copy(thrust::host, A, A + N, result, g);
// result is now {6, 5, 8, 7, 2, 1, 4, 3, 10, 9}

Template Parameters:

  • DerivedPolicy The name of the derived execution policy.
  • RandomIterator is a random access iterator
  • OutputIterator is a model of Output Iterator.
  • URBG is a uniform random bit generator

Function Parameters:

  • exec The execution policy to use for parallelization.
  • first The beginning of the sequence to shuffle.
  • last The end of the sequence to shuffle.
  • result Destination of shuffled sequence
  • g A UniformRandomBitGenerator

See: shuffle

Function shuffle_copy

template <typename RandomIterator,   typename OutputIterator,   typename URBG> _CCCL_HOST_DEVICE void shuffle_copy(RandomIterator first,   RandomIterator last,   OutputIterator result,   URBG && g); shuffle_copy differs from shuffle only in that the reordered sequence is written to different output sequences, rather than in place. shuffle_copy reorders the elements [first, last) by a uniform pseudorandom permutation, defined by random engine g.

The following code snippet demonstrates how to use shuffle_copy to create a random permutation.

#include <thrust/shuffle.h>
#include <thrust/random.h>
int A[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int result[10];
const int N = sizeof(A)/sizeof(int);
thrust::default_random_engine g;
thrust::shuffle_copy(A, A + N, result, g);
// result is now {6, 5, 8, 7, 2, 1, 4, 3, 10, 9}

Template Parameters:

  • RandomIterator is a random access iterator
  • OutputIterator is a model of Output Iterator.
  • URBG is a uniform random bit generator

Function Parameters:

  • first The beginning of the sequence to shuffle.
  • last The end of the sequence to shuffle.
  • result Destination of shuffled sequence
  • g A UniformRandomBitGenerator

See: shuffle