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_TRANSFORM_HPP
12 #define BOOST_COMPUTE_ALGORITHM_TRANSFORM_HPP
14 #include <boost/static_assert.hpp>
16 #include <boost/compute/system.hpp>
17 #include <boost/compute/command_queue.hpp>
18 #include <boost/compute/algorithm/copy.hpp>
19 #include <boost/compute/iterator/transform_iterator.hpp>
20 #include <boost/compute/iterator/zip_iterator.hpp>
21 #include <boost/compute/functional/detail/unpack.hpp>
22 #include <boost/compute/type_traits/is_device_iterator.hpp>
27 /// Transforms the elements in the range [\p first, \p last) using
28 /// operator \p op and stores the results in the range beginning at
31 /// For example, to calculate the absolute value for each element in a vector:
33 /// \snippet test/test_transform.cpp transform_abs
35 /// Space complexity: \Omega(1)
38 template<class InputIterator, class OutputIterator, class UnaryOperator>
39 inline OutputIterator transform(InputIterator first,
41 OutputIterator result,
43 command_queue &queue = system::default_queue())
45 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
46 BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
48 ::boost::compute::make_transform_iterator(first, op),
49 ::boost::compute::make_transform_iterator(last, op),
56 template<class InputIterator1,
60 inline OutputIterator transform(InputIterator1 first1,
62 InputIterator2 first2,
63 OutputIterator result,
65 command_queue &queue = system::default_queue())
67 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator1>::value);
68 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator2>::value);
69 BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
71 typedef typename std::iterator_traits<InputIterator1>::difference_type difference_type;
73 difference_type n = std::distance(first1, last1);
76 ::boost::compute::make_zip_iterator(boost::make_tuple(first1, first2)),
77 ::boost::compute::make_zip_iterator(boost::make_tuple(last1, first2 + n)),
84 } // end compute namespace
85 } // end boost namespace
87 #endif // BOOST_COMPUTE_ALGORITHM_TRANSFORM_HPP