thrust::transform_inclusive_scan
Defined in thrust/transform_scan.h
-
template<typename DerivedPolicy, typename InputIterator, typename OutputIterator, typename UnaryFunction, typename AssociativeOperator>
OutputIterator thrust::transform_inclusive_scan(const thrust::detail::execution_policy_base<DerivedPolicy> &exec, InputIterator first, InputIterator last, OutputIterator result, UnaryFunction unary_op, AssociativeOperator binary_op) transform_inclusive_scanfuses thetransformandinclusive_scanoperations.transform_inclusive_scanis equivalent to performing a transformation defined byunary_opinto a temporary sequence and then performing aninclusive_scanon the transformed sequence. In most cases, fusing these two operations together is more efficient, since fewer memory reads and writes are required. Intransform_inclusive_scan,unary_op(*first)is assigned to*resultand the result ofbinary_op(unary_op(*first), unary_op(*(first + 1)))is assigned to*(result + 1), and so on. The transform scan operation is permitted to be in-place.The algorithm’s execution is parallelized as determined by
exec.The following code snippet demonstrates how to use
transform_inclusive_scanusing thethrust::hostexecution policy for parallelization:#include <thrust/transform_scan.h> #include <thrust/execution_policy.h> ... int data[6] = {1, 0, 2, 2, 1, 3}; thrust::negate<int> unary_op; thrust::plus<int> binary_op; thrust::transform_inclusive_scan(thrust::host, data, data + 6, data, unary_op, binary_op); // in-place scan // data is now {-1, -1, -3, -5, -6, -9}
See also
transformSee also
inclusive_scan- Parameters
exec – The execution policy to use for parallelization.
first – The beginning of the input sequence.
last – The end of the input sequence.
result – The beginning of the output sequence.
unary_op – The function used to transform the input sequence.
binary_op – The associative operator used to ‘sum’ transformed values.
- Template Parameters
DerivedPolicy – The name of the derived execution policy.
InputIterator – is a model of Input Iterator and
InputIterator'svalue_typeis convertible tounary_op'sinput type.OutputIterator – is a model of Output Iterator.
UnaryFunction – accepts inputs of
InputIterator'svalue_type. The functions return type must be convertible toOutputIterator'svalue_type.AssociativeOperator – is a binary function and the function’s return type must be convertible to
OutputIterator'svalue_type.
- Returns
The end of the output sequence.
- Pre
firstmay equalresult, but the range[first, last)and the range[result, result + (last - first))shall not overlap otherwise.