boost::compute::exclusive_scan
// In header: <boost/compute/algorithm/exclusive_scan.hpp> template<typename InputIterator, typename OutputIterator, typename T, typename BinaryOperator> OutputIterator exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init, BinaryOperator binary_op, command_queue & queue = system::default_queue()); template<typename InputIterator, typename OutputIterator, typename T> OutputIterator exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, T init, command_queue & queue = system::default_queue()); template<typename InputIterator, typename OutputIterator> OutputIterator exclusive_scan(InputIterator first, InputIterator last, OutputIterator result, command_queue & queue = system::default_queue());
Performs an exclusive 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 all the previous values 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::exclusive_scan( input.begin(), input.end(), output.begin(), queue ); // output = [ 0, 1, 3, 6 ]
But different associative operation can be specified as binary_op
instead (e.g., multiplication, maximum, minimum). Also value used to initialized the scan sequence can be specified.
// 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); // exclusive_scan with multiplication // initial value equals 10 boost::compute::exclusive_scan( input.begin(), input.end(), output.begin(), int(10), boost::compute::multiplies<int>(), queue ); // output = [10, 10, 20, 20, 40]
See Also:
inclusive_scan()
Parameters: |
|
||||||||||||
Returns: |
|