Template Function thrust::exclusive_scan_by_key(InputIterator1, InputIterator1, InputIterator2, OutputIterator)¶
Function Documentation¶
-
template<typename
InputIterator1
, typenameInputIterator2
, typenameOutputIterator
>
OutputIteratorthrust
::
exclusive_scan_by_key
(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result) exclusive_scan_by_key
computes an exclusive segmented prefixThis version of
exclusive_scan_by_key
uses the value0
to initialize the exclusive scan operation.This version of
exclusive_scan_by_key
assumesplus
as the associative operator used to perform the prefix sum. When the input and output sequences are the same, the scan is performed in-place.This version of
exclusive_scan_by_key
assumesequal_to
as the binary predicate used to compare adjacent keys. Specifically, consecutive iteratorsi
andi+1
in the range[first1, last1
belong to the same segment if*i == *(i+1)
, and belong to different segments otherwise.Refer to the most general form of
exclusive_scan_by_key
for additional details.The following code snippet demonstrates how to use
exclusive_scan_by_key
.- Pre
first1
may equalresult
but the range[first1, last1)
and the range[result, result + (last1 - first1))
shall not overlap otherwise.- Pre
first2
may equalresult
but the range[first2, first2 + (last1 - first1)
and range[result, result + (last1 - first1))
shall not overlap otherwise.- Parameters
first1
: The beginning of the key sequence.last1
: The end of the key sequence.first2
: The beginning of the input value sequence.result
: The beginning of the output value sequence.
#include <thrust/scan.h> int keys[10] = {0, 0, 0, 1, 1, 2, 3, 3, 3, 3}; int vals[10] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; thrust::exclusive_scan_by_key(key, key + 10, vals, vals); // in-place scan // vals is now {0, 1, 2, 0, 1, 0, 0, 1, 2, 3};
- See
exclusive_scan