]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | //---------------------------------------------------------------------------// |
2 | // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com> | |
3 | // | |
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 | |
7 | // | |
8 | // See http://boostorg.github.com/compute for more information. | |
9 | //---------------------------------------------------------------------------// | |
10 | ||
11 | #ifndef BOOST_COMPUTE_ALGORITHM_INCLUSIVE_SCAN_HPP | |
12 | #define BOOST_COMPUTE_ALGORITHM_INCLUSIVE_SCAN_HPP | |
13 | ||
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> | |
18 | ||
19 | namespace boost { | |
20 | namespace compute { | |
21 | ||
22 | /// Performs an inclusive scan of the elements in the range [\p first, \p last) | |
23 | /// and stores the results in the range beginning at \p result. | |
24 | /// | |
25 | /// Each element in the output is assigned to the sum of the current value in | |
26 | /// the input with the sum of every previous value in the input. | |
27 | /// | |
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 binary_op associative binary operator | |
32 | /// \param queue command queue to perform the operation | |
33 | /// | |
34 | /// \return \c OutputIterator to the end of the result range | |
35 | /// | |
36 | /// The default operation is to add the elements up. | |
37 | /// | |
38 | /// \snippet test/test_scan.cpp inclusive_scan_int | |
39 | /// | |
40 | /// But different associative operation can be specified as \p binary_op | |
41 | /// instead (e.g., multiplication, maximum, minimum). | |
42 | /// | |
43 | /// \snippet test/test_scan.cpp inclusive_scan_int_multiplies | |
44 | /// | |
45 | /// \see exclusive_scan() | |
46 | template<class InputIterator, class OutputIterator, class BinaryOperator> | |
47 | inline OutputIterator | |
48 | inclusive_scan(InputIterator first, | |
49 | InputIterator last, | |
50 | OutputIterator result, | |
51 | BinaryOperator binary_op, | |
52 | command_queue &queue = system::default_queue()) | |
53 | { | |
54 | typedef typename | |
55 | std::iterator_traits<OutputIterator>::value_type output_type; | |
56 | ||
57 | return detail::scan(first, last, result, false, | |
58 | output_type(0), binary_op, | |
59 | queue); | |
60 | } | |
61 | ||
62 | /// \overload | |
63 | template<class InputIterator, class OutputIterator> | |
64 | inline OutputIterator | |
65 | inclusive_scan(InputIterator first, | |
66 | InputIterator last, | |
67 | OutputIterator result, | |
68 | command_queue &queue = system::default_queue()) | |
69 | { | |
70 | typedef typename | |
71 | std::iterator_traits<OutputIterator>::value_type output_type; | |
72 | ||
73 | return detail::scan(first, last, result, false, | |
74 | output_type(0), boost::compute::plus<output_type>(), | |
75 | queue); | |
76 | } | |
77 | ||
78 | } // end compute namespace | |
79 | } // end boost namespace | |
80 | ||
81 | #endif // BOOST_COMPUTE_ALGORITHM_INCLUSIVE_SCAN_HPP |