thrust::transform_inclusive_scan

Defined in thrust/transform_scan.h

template<typename InputIterator, typename OutputIterator, typename UnaryFunction, typename T, typename AssociativeOperator>
OutputIterator thrust::transform_inclusive_scan(InputIterator first, InputIterator last, OutputIterator result, UnaryFunction unary_op, T init, AssociativeOperator binary_op)

transform_inclusive_scan fuses the transform and inclusive_scan operations. transform_inclusive_scan is equivalent to performing a tranformation defined by unary_op into a temporary sequence and then performing an inclusive_scan on the tranformed sequence. In most cases, fusing these two operations together is more efficient, since fewer memory reads and writes are required.In transform_inclusive_scan, if binary_op(init, unary_op(*first)) is accum, it is assigned to *result and the result of binary_op(accum, unary_op(*(first + 1))) is assigned to *(result + 1), and so on. The transform scan operation is permitted to be in-place.

The following code snippet demonstrates how to use transform_inclusive_scan

#include <thrust/transform_scan.h>
...

int data[6] = {1, 0, 2, 2, 1, 3};

thrust::negate<int> unary_op;
thrust::plus<int> binary_op;

thrust::transform_inclusive_scan(data, data + 6, data, unary_op, 4, binary_op); // in-place scan

// data is now {3, 3, 1, -1, -2, -5}

See also

transform

See also

inclusive_scan

Parameters
  • 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 tranform the input sequence.

  • init – The initial value of the transform_inclusive_scan

  • binary_op – The associative operator used to ‘sum’ transformed values.

Template Parameters
  • InputIterator – is a model of Input Iterator and InputIterator's value_type is convertible to unary_op's input type.

  • OutputIterator – is a model of Output Iterator.

  • UnaryFunction – is a model of Unary Function and accepts inputs of InputIterator's value_type. UnaryFunction's result_type is convertable to OutputIterator's value_type.

  • T – is convertible to OutputIterator's value_type.

  • AssociativeOperator – is a model of <ahref=”https://en.cppreference.com/w/cpp/utility/functional/binary_function”> Binary Function and AssociativeOperator's result_type is convertible to OutputIterator's value_type.

Returns

The end of the output sequence.

Pre

first may equal result, but the range [first, last) and the range [result, result + (last - first)) shall not overlap otherwise.