]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/transform.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / compute / algorithm / transform.hpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
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
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10
11 #ifndef BOOST_COMPUTE_ALGORITHM_TRANSFORM_HPP
12 #define BOOST_COMPUTE_ALGORITHM_TRANSFORM_HPP
13
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>
20
21 namespace boost {
22 namespace compute {
23
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
26 /// \p result.
27 ///
28 /// For example, to calculate the absolute value for each element in a vector:
29 ///
30 /// \snippet test/test_transform.cpp transform_abs
31 ///
32 /// Space complexity: \Omega(1)
33 ///
34 /// \see copy()
35 template<class InputIterator, class OutputIterator, class UnaryOperator>
36 inline OutputIterator transform(InputIterator first,
37 InputIterator last,
38 OutputIterator result,
39 UnaryOperator op,
40 command_queue &queue = system::default_queue())
41 {
42 return copy(
43 ::boost::compute::make_transform_iterator(first, op),
44 ::boost::compute::make_transform_iterator(last, op),
45 result,
46 queue
47 );
48 }
49
50 /// \overload
51 template<class InputIterator1,
52 class InputIterator2,
53 class OutputIterator,
54 class BinaryOperator>
55 inline OutputIterator transform(InputIterator1 first1,
56 InputIterator1 last1,
57 InputIterator2 first2,
58 OutputIterator result,
59 BinaryOperator op,
60 command_queue &queue = system::default_queue())
61 {
62 typedef typename std::iterator_traits<InputIterator1>::difference_type difference_type;
63
64 difference_type n = std::distance(first1, last1);
65
66 return transform(
67 make_zip_iterator(boost::make_tuple(first1, first2)),
68 make_zip_iterator(boost::make_tuple(last1, first2 + n)),
69 result,
70 detail::unpack(op),
71 queue
72 );
73 }
74
75 } // end compute namespace
76 } // end boost namespace
77
78 #endif // BOOST_COMPUTE_ALGORITHM_TRANSFORM_HPP