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/compute/system.hpp>
15 #include <boost/compute/command_queue.hpp>
16 #include <boost/compute/algorithm/copy.hpp>
17 #include <boost/compute/iterator/transform_iterator.hpp>
18 #include <boost/compute/iterator/zip_iterator.hpp>
19 #include <boost/compute/functional/detail/unpack.hpp>
24 /// Transforms the elements in the range [\p first, \p last) using
25 /// operator \p op and stores the results in the range beginning at
28 /// For example, to calculate the absolute value for each element in a vector:
30 /// \snippet test/test_transform.cpp transform_abs
32 /// Space complexity: \Omega(1)
35 template<class InputIterator, class OutputIterator, class UnaryOperator>
36 inline OutputIterator transform(InputIterator first,
38 OutputIterator result,
40 command_queue &queue = system::default_queue())
43 ::boost::compute::make_transform_iterator(first, op),
44 ::boost::compute::make_transform_iterator(last, op),
51 template<class InputIterator1,
55 inline OutputIterator transform(InputIterator1 first1,
57 InputIterator2 first2,
58 OutputIterator result,
60 command_queue &queue = system::default_queue())
62 typedef typename std::iterator_traits<InputIterator1>::difference_type difference_type;
64 difference_type n = std::distance(first1, last1);
67 make_zip_iterator(boost::make_tuple(first1, first2)),
68 make_zip_iterator(boost::make_tuple(last1, first2 + n)),
75 } // end compute namespace
76 } // end boost namespace
78 #endif // BOOST_COMPUTE_ALGORITHM_TRANSFORM_HPP