• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_IOTA_HPP
12 #define BOOST_COMPUTE_ALGORITHM_IOTA_HPP
13 
14 #include <boost/static_assert.hpp>
15 
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/counting_iterator.hpp>
20 #include <boost/compute/type_traits/is_device_iterator.hpp>
21 
22 namespace boost {
23 namespace compute {
24 
25 /// Fills the range [\p first, \p last) with sequential values starting at
26 /// \p value.
27 ///
28 /// For example, the following code:
29 /// \snippet test/test_iota.cpp iota
30 ///
31 /// Will fill \c vec with the values (\c 0, \c 1, \c 2, \c ...).
32 ///
33 /// Space complexity: \Omega(1)
34 template<class BufferIterator, class T>
iota(BufferIterator first,BufferIterator last,const T & value,command_queue & queue=system::default_queue ())35 inline void iota(BufferIterator first,
36                  BufferIterator last,
37                  const T &value,
38                  command_queue &queue = system::default_queue())
39 {
40     BOOST_STATIC_ASSERT(is_device_iterator<BufferIterator>::value);
41     T count = static_cast<T>(detail::iterator_range_size(first, last));
42 
43     copy(
44         ::boost::compute::make_counting_iterator(value),
45         ::boost::compute::make_counting_iterator(value + count),
46         first,
47         queue
48     );
49 }
50 
51 } // end compute namespace
52 } // end boost namespace
53 
54 #endif // BOOST_COMPUTE_ALGORITHM_IOTA_HPP
55