1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_ALGORITHM_EXCLUSIVE_SCAN_HPP
12 #define BOOST_COMPUTE_ALGORITHM_EXCLUSIVE_SCAN_HPP
14 #include <boost/compute/functional.hpp>
15 #include <boost/compute/system.hpp>
16 #include <boost/compute/command_queue.hpp>
17 #include <boost/compute/algorithm/detail/scan.hpp>
22 /// Performs an exclusive scan of the elements in the range [\p first, \p last)
23 /// and stores the results in the range beginning at \p result.
25 /// Each element in the output is assigned to the sum of all the previous
26 /// values in the input.
28 /// \param first first element in the range to scan
29 /// \param last last element in the range to scan
30 /// \param result first element in the result range
31 /// \param init value used to initialize the scan sequence
32 /// \param binary_op associative binary operator
33 /// \param queue command queue to perform the operation
35 /// \return \c OutputIterator to the end of the result range
37 /// The default operation is to add the elements up.
39 /// \snippet test/test_scan.cpp exclusive_scan_int
41 /// But different associative operation can be specified as \p binary_op
42 /// instead (e.g., multiplication, maximum, minimum). Also value used to
43 /// initialized the scan sequence can be specified.
45 /// \snippet test/test_scan.cpp exclusive_scan_int_multiplies
47 /// \see inclusive_scan()
48 template<class InputIterator, class OutputIterator, class T, class BinaryOperator>
50 exclusive_scan(InputIterator first,
52 OutputIterator result,
54 BinaryOperator binary_op,
55 command_queue &queue = system::default_queue())
57 return detail::scan(first, last, result, true, init, binary_op, queue);
61 template<class InputIterator, class OutputIterator, class T>
63 exclusive_scan(InputIterator first,
65 OutputIterator result,
67 command_queue &queue = system::default_queue())
70 std::iterator_traits<OutputIterator>::value_type output_type;
72 return detail::scan(first, last, result, true,
73 init, boost::compute::plus<output_type>(),
78 template<class InputIterator, class OutputIterator>
80 exclusive_scan(InputIterator first,
82 OutputIterator result,
83 command_queue &queue = system::default_queue())
86 std::iterator_traits<OutputIterator>::value_type output_type;
88 return detail::scan(first, last, result, true,
89 output_type(0), boost::compute::plus<output_type>(),
93 } // end compute namespace
94 } // end boost namespace
96 #endif // BOOST_COMPUTE_ALGORITHM_EXCLUSIVE_SCAN_HPP