thrust::sequence
Defined in thrust/sequence.h
-
template<typename DerivedPolicy, typename ForwardIterator, typename T>
void thrust::sequence(const thrust::detail::execution_policy_base<DerivedPolicy> &exec, ForwardIterator first, ForwardIterator last, T init, T step) sequence
fills the range[first, last)
with a sequence of numbers.For each iterator
i
in the range[first, last)
, this version ofsequence
performs the assignment*i = init + step * (i - first)
.The algorithm’s execution is parallelized as determined by
exec
.The following code snippet demonstrates how to use
sequence
to fill a range with a sequence of numbers starting from the value 1 with a step size of 3 using thethrust::host
execution policy for parallelization:#include <thrust/sequence.h> #include <thrust/execution_policy.h> ... const int N = 10; int A[N]; thrust::sequence(thrust::host, A, A + 10, 1, 3); // A is now {1, 4, 7, 10, 13, 16, 19, 22, 25, 28}
Note
Unlike the similar C++ STL function
std::iota
,sequence
offers no guarantee on order of execution.- Parameters
exec – The execution policy to use for parallelization.
first – The beginning of the sequence.
last – The end of the sequence.
init – The first value of the sequence of numbers
step – The difference between consecutive elements.
- Template Parameters
DerivedPolicy – The name of the derived execution policy.
ForwardIterator – is a model of Forward Iterator, and
ForwardIterator
is mutable, and ifx
andy
are objects ofForwardIterator's
value_type
, thenx + y
is defined, and ifT
isForwardIterator's
value_type
, thenT(0)
is defined.T – is a model of Assignable, and
T
is convertible toForwardIterator's
value_type
.