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_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_TRANSFORM_HPP
0013
0014 #include <boost/static_assert.hpp>
0015
0016 #include <boost/compute/system.hpp>
0017 #include <boost/compute/command_queue.hpp>
0018 #include <boost/compute/algorithm/copy.hpp>
0019 #include <boost/compute/iterator/transform_iterator.hpp>
0020 #include <boost/compute/iterator/zip_iterator.hpp>
0021 #include <boost/compute/functional/detail/unpack.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 template<class InputIterator, class OutputIterator, class UnaryOperator>
0039 inline OutputIterator transform(InputIterator first,
0040 InputIterator last,
0041 OutputIterator result,
0042 UnaryOperator op,
0043 command_queue &queue = system::default_queue())
0044 {
0045 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0046 BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
0047 return copy(
0048 ::boost::compute::make_transform_iterator(first, op),
0049 ::boost::compute::make_transform_iterator(last, op),
0050 result,
0051 queue
0052 );
0053 }
0054
0055
0056 template<class InputIterator1,
0057 class InputIterator2,
0058 class OutputIterator,
0059 class BinaryOperator>
0060 inline OutputIterator transform(InputIterator1 first1,
0061 InputIterator1 last1,
0062 InputIterator2 first2,
0063 OutputIterator result,
0064 BinaryOperator op,
0065 command_queue &queue = system::default_queue())
0066 {
0067 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator1>::value);
0068 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator2>::value);
0069 BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
0070
0071 typedef typename std::iterator_traits<InputIterator1>::difference_type difference_type;
0072
0073 difference_type n = std::distance(first1, last1);
0074
0075 return transform(
0076 ::boost::compute::make_zip_iterator(boost::make_tuple(first1, first2)),
0077 ::boost::compute::make_zip_iterator(boost::make_tuple(last1, first2 + n)),
0078 result,
0079 detail::unpack(op),
0080 queue
0081 );
0082 }
0083
0084 }
0085 }
0086
0087 #endif