Function inclusive_scan

| Home | Libraries | People | FAQ | More

## Function inclusive_scan

boost::compute::inclusive_scan

## Synopsis

    // In header: <boost/compute/algorithm/inclusive_scan.hpp>

    template<typename InputIterator, typename OutputIterator,
             typename BinaryOperator>
      OutputIterator
      inclusive_scan(InputIterator first, InputIterator last,
                     OutputIterator result, BinaryOperator binary_op,
                     command_queue & queue = system::default_queue());
    template<typename InputIterator, typename OutputIterator>
      OutputIterator
      inclusive_scan(InputIterator first, InputIterator last,
                     OutputIterator result,
                     command_queue & queue = system::default_queue());

## Description

Performs an inclusive scan of the elements in the range [`first`, `last`) and stores the results in the range beginning at `result`.

Each element in the output is assigned to the sum of the current value in the input with the sum of every previous value in the input.

The default operation is to add the elements up.

    // setup input
    int data[] = { 1, 2, 3, 4 };
    boost::compute::vector<int> input(data, data + 4, queue);

    // setup output
    boost::compute::vector<int> output(4, context);

    // scan values
    boost::compute::inclusive_scan(
        input.begin(), input.end(), output.begin(), queue
    );

    // output = [ 1, 3, 6, 10 ]

But different associative operation can be specified as `binary_op` instead (e.g., multiplication, maximum, minimum).

    // setup input
    int data[] = { 1, 2, 1, 2, 3 };
    boost::compute::vector<int> input(data, data + 5, queue);

    // setup output
    boost::compute::vector<int> output(5, context);

    // inclusive scan with multiplication
    boost::compute::inclusive_scan(
        input.begin(), input.end(), output.begin(),
        boost::compute::multiplies<int>(), queue
    );

    // output = [1, 2, 2, 4, 12]

See Also:

exclusive_scan()

Parameters:

`binary_op` | associative binary operator
`first` | first element in the range to scan
`last` | last element in the range to scan
`queue` | command queue to perform the operation
`result` | first element in the result range

Returns: | `OutputIterator` to the end of the result range