thrust::generate#
Overloads#
generate(exec, first, last, gen)#
-
template<typename DerivedPolicy, typename ForwardIterator, typename Generator>
void thrust::generate( - const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
- ForwardIterator first,
- ForwardIterator last,
- Generator gen,
generateassigns the result of invokinggen, a function object that takes no arguments, to each element in the range[first,last).The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to fill a
host_vectorwith random numbers, using the standard C library functionrandusing thethrust::hostexecution policy for parallelization:#include <thrust/generate.h> #include <thrust/host_vector.h> #include <thrust/execution_policy.h> #include <cstdlib> ... thrust::host_vector<int> v(10); srand(13); thrust::generate(thrust::host, v.begin(), v.end(), rand); // the elements of v are now pseudo-random numbers
See also
- Parameters:
exec – The execution policy to use for parallelization.
first – The first element in the range of interest.
last – The last element in the range of interest.
gen – A function argument, taking no parameters, used to generate values to assign to elements in the range
[first,last).
- Template Parameters:
DerivedPolicy – The name of the derived execution policy.
ForwardIterator – is a model of Forward Iterator, and
ForwardIteratoris mutable.Generator – A nullary function with a return type convertible to
ForwardIterator'svalue_type.
generate(first, last, gen)#
-
template<typename ForwardIterator, typename Generator>
void thrust::generate( - ForwardIterator first,
- ForwardIterator last,
- Generator gen,
generateassigns the result of invokinggen, a function object that takes no arguments, to each element in the range[first,last).The following code snippet demonstrates how to fill a
host_vectorwith random numbers, using the standard C library functionrand.#include <thrust/generate.h> #include <thrust/host_vector.h> #include <thrust/execution_policy.h> #include <cstdlib> ... thrust::host_vector<int> v(10); srand(13); thrust::generate(v.begin(), v.end(), rand); // the elements of v are now pseudo-random numbers
See also
- Parameters:
first – The first element in the range of interest.
last – The last element in the range of interest.
gen – A function argument, taking no parameters, used to generate values to assign to elements in the range
[first,last).
- Template Parameters:
ForwardIterator – is a model of Forward Iterator, and
ForwardIteratoris mutable.Generator – A nullary function with a return type convertible to
ForwardIterator'svalue_type.