Template Function thrust::exclusive_scan_by_key(InputIterator1, InputIterator1, InputIterator2, OutputIterator, T, BinaryPredicate, AssociativeOperator)¶
Function Documentation¶
-
template<typename
InputIterator1, typenameInputIterator2, typenameOutputIterator, typenameT, typenameBinaryPredicate, typenameAssociativeOperator>
OutputIteratorthrust::exclusive_scan_by_key(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, OutputIterator result, T init, BinaryPredicate binary_pred, AssociativeOperator binary_op) exclusive_scan_by_keycomputes an exclusive key-value or ‘segmented’ prefix sum operation. The term ‘exclusive’ means that each result does not include the corresponding input operand in the partial sum. The term ‘segmented’ means that the partial sums are broken into distinct segments. In other words, within each segment a separate exclusive scan operation is computed. Refer to the code sample below for example usage.This version of
exclusive_scan_by_keyuses the valueinitto initialize the exclusive scan operation.This version of
exclusive_scan_by_keyuses the binary predicatebinary_predto compare adjacent keys. Specifically, consecutive iteratorsiandi+1in the range[first1, last1)belong to the same segment ifbinary_pred(*i, *(i+1))is true, and belong to different segments otherwise.This version of
exclusive_scan_by_keyuses the associative operatorbinary_opto perform the prefix sum. When the input and output sequences are the same, the scan is performed in-place.The following code snippet demonstrates how to use
exclusive_scan_by_key- Return
The end of the output sequence.
- Pre
first1may equalresultbut the range[first1, last1)and the range[result, result + (last1 - first1))shall not overlap otherwise.- Pre
first2may equalresultbut 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.init: The initial of the exclusive sum value.binary_pred: The binary predicate used to determine equality of keys.binary_op: The associatve operator used to ‘sum’ values.
- Template Parameters
InputIterator1: is a model of Input IteratorInputIterator2: is a model of Input Iterator andInputIterator2'svalue_typeis convertible toOutputIterator'svalue_type.OutputIterator: is a model of Output Iterator, and ifxandyare objects ofOutputIterator'svalue_type, thenbinary_op(x,y)is defined.T: is convertible toOutputIterator'svalue_type.BinaryPredicate: is a model of Binary Predicate.AssociativeOperator: is a model of Binary Function andAssociativeOperator'sresult_typeis convertible toOutputIterator'svalue_type.
#include <thrust/scan.h> #include <thrust/functional.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}; int init = 5; thrust::equal_to<int> binary_pred; thrust::plus<int> binary_op; thrust::exclusive_scan_by_key(key, key + 10, vals, vals, init, binary_pred, binary_op); // in-place scan // vals is now {5, 6, 7, 5, 6, 5, 5, 6, 7, 8};
- See
exclusive_scan
- See
inclusive_scan_by_key