File indexing completed on 2025-01-18 09:29:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_ALGORITHM_REDUCE_BY_KEY_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_REDUCE_BY_KEY_HPP
0013
0014 #include <iterator>
0015 #include <utility>
0016
0017 #include <boost/static_assert.hpp>
0018
0019 #include <boost/compute/command_queue.hpp>
0020 #include <boost/compute/device.hpp>
0021 #include <boost/compute/functional.hpp>
0022 #include <boost/compute/system.hpp>
0023 #include <boost/compute/algorithm/detail/reduce_by_key.hpp>
0024 #include <boost/compute/type_traits/is_device_iterator.hpp>
0025
0026 namespace boost {
0027 namespace compute {
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 template<class InputKeyIterator, class InputValueIterator,
0062 class OutputKeyIterator, class OutputValueIterator,
0063 class BinaryFunction, class BinaryPredicate>
0064 inline std::pair<OutputKeyIterator, OutputValueIterator>
0065 reduce_by_key(InputKeyIterator keys_first,
0066 InputKeyIterator keys_last,
0067 InputValueIterator values_first,
0068 OutputKeyIterator keys_result,
0069 OutputValueIterator values_result,
0070 BinaryFunction function,
0071 BinaryPredicate predicate,
0072 command_queue &queue = system::default_queue())
0073 {
0074 BOOST_STATIC_ASSERT(is_device_iterator<InputKeyIterator>::value);
0075 BOOST_STATIC_ASSERT(is_device_iterator<InputValueIterator>::value);
0076 BOOST_STATIC_ASSERT(is_device_iterator<OutputKeyIterator>::value);
0077 BOOST_STATIC_ASSERT(is_device_iterator<OutputValueIterator>::value);
0078
0079 return detail::dispatch_reduce_by_key(keys_first, keys_last, values_first,
0080 keys_result, values_result,
0081 function, predicate,
0082 queue);
0083 }
0084
0085
0086 template<class InputKeyIterator, class InputValueIterator,
0087 class OutputKeyIterator, class OutputValueIterator,
0088 class BinaryFunction>
0089 inline std::pair<OutputKeyIterator, OutputValueIterator>
0090 reduce_by_key(InputKeyIterator keys_first,
0091 InputKeyIterator keys_last,
0092 InputValueIterator values_first,
0093 OutputKeyIterator keys_result,
0094 OutputValueIterator values_result,
0095 BinaryFunction function,
0096 command_queue &queue = system::default_queue())
0097 {
0098 BOOST_STATIC_ASSERT(is_device_iterator<InputKeyIterator>::value);
0099 BOOST_STATIC_ASSERT(is_device_iterator<InputValueIterator>::value);
0100 BOOST_STATIC_ASSERT(is_device_iterator<OutputKeyIterator>::value);
0101 BOOST_STATIC_ASSERT(is_device_iterator<OutputValueIterator>::value);
0102 typedef typename std::iterator_traits<InputKeyIterator>::value_type key_type;
0103
0104 return reduce_by_key(keys_first, keys_last, values_first,
0105 keys_result, values_result,
0106 function, equal_to<key_type>(),
0107 queue);
0108 }
0109
0110
0111 template<class InputKeyIterator, class InputValueIterator,
0112 class OutputKeyIterator, class OutputValueIterator>
0113 inline std::pair<OutputKeyIterator, OutputValueIterator>
0114 reduce_by_key(InputKeyIterator keys_first,
0115 InputKeyIterator keys_last,
0116 InputValueIterator values_first,
0117 OutputKeyIterator keys_result,
0118 OutputValueIterator values_result,
0119 command_queue &queue = system::default_queue())
0120 {
0121 BOOST_STATIC_ASSERT(is_device_iterator<InputKeyIterator>::value);
0122 BOOST_STATIC_ASSERT(is_device_iterator<InputValueIterator>::value);
0123 BOOST_STATIC_ASSERT(is_device_iterator<OutputKeyIterator>::value);
0124 BOOST_STATIC_ASSERT(is_device_iterator<OutputValueIterator>::value);
0125 typedef typename std::iterator_traits<InputKeyIterator>::value_type key_type;
0126 typedef typename std::iterator_traits<InputValueIterator>::value_type value_type;
0127
0128 return reduce_by_key(keys_first, keys_last, values_first,
0129 keys_result, values_result,
0130 plus<value_type>(), equal_to<key_type>(),
0131 queue);
0132 }
0133
0134 }
0135 }
0136
0137 #endif