File indexing completed on 2025-01-18 09:29:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_ALGORITHM_TRANSFORM_REDUCE_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_TRANSFORM_REDUCE_HPP
0013
0014 #include <boost/static_assert.hpp>
0015
0016 #include <boost/compute/system.hpp>
0017 #include <boost/compute/algorithm/reduce.hpp>
0018 #include <boost/compute/iterator/transform_iterator.hpp>
0019 #include <boost/compute/iterator/zip_iterator.hpp>
0020 #include <boost/compute/functional/detail/unpack.hpp>
0021 #include <boost/compute/detail/iterator_range_size.hpp>
0022 #include <boost/compute/type_traits/is_device_iterator.hpp>
0023
0024 namespace boost {
0025 namespace compute {
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 template<class InputIterator,
0041 class OutputIterator,
0042 class UnaryTransformFunction,
0043 class BinaryReduceFunction>
0044 inline void transform_reduce(InputIterator first,
0045 InputIterator last,
0046 OutputIterator result,
0047 UnaryTransformFunction transform_function,
0048 BinaryReduceFunction reduce_function,
0049 command_queue &queue = system::default_queue())
0050 {
0051 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0052 ::boost::compute::reduce(
0053 ::boost::compute::make_transform_iterator(first, transform_function),
0054 ::boost::compute::make_transform_iterator(last, transform_function),
0055 result,
0056 reduce_function,
0057 queue
0058 );
0059 }
0060
0061
0062 template<class InputIterator1,
0063 class InputIterator2,
0064 class OutputIterator,
0065 class BinaryTransformFunction,
0066 class BinaryReduceFunction>
0067 inline void transform_reduce(InputIterator1 first1,
0068 InputIterator1 last1,
0069 InputIterator2 first2,
0070 OutputIterator result,
0071 BinaryTransformFunction transform_function,
0072 BinaryReduceFunction reduce_function,
0073 command_queue &queue = system::default_queue())
0074 {
0075 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator1>::value);
0076 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator2>::value);
0077 BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
0078
0079 typedef typename std::iterator_traits<InputIterator1>::difference_type difference_type;
0080
0081 difference_type n = std::distance(first1, last1);
0082
0083 ::boost::compute::transform_reduce(
0084 ::boost::compute::make_zip_iterator(
0085 boost::make_tuple(first1, first2)
0086 ),
0087 ::boost::compute::make_zip_iterator(
0088 boost::make_tuple(last1, first2 + n)
0089 ),
0090 result,
0091 detail::unpack(transform_function),
0092 reduce_function,
0093 queue
0094 );
0095 }
0096
0097 }
0098 }
0099
0100 #endif