Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:56

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_ALGORITHM_GENERATE_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_GENERATE_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/function_input_iterator.hpp>
0020 #include <boost/compute/detail/iterator_range_size.hpp>
0021 #include <boost/compute/type_traits/is_device_iterator.hpp>
0022 
0023 namespace boost {
0024 namespace compute {
0025 
0026 /// Stores the result of \p generator for each element in the range
0027 /// [\p first, \p last).
0028 ///
0029 /// Space complexity: \Omega(1)
0030 template<class OutputIterator, class Generator>
0031 inline void generate(OutputIterator first,
0032                      OutputIterator last,
0033                      Generator generator,
0034                      command_queue &queue = system::default_queue())
0035 {
0036     BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
0037     size_t count = detail::iterator_range_size(first, last);
0038     if(count == 0){
0039         return;
0040     }
0041 
0042     ::boost::compute::copy(
0043         ::boost::compute::make_function_input_iterator(generator,
0044                                                        first.get_index()),
0045         ::boost::compute::make_function_input_iterator(generator,
0046                                                        last.get_index()),
0047         first,
0048         queue
0049     );
0050 }
0051 
0052 } // end compute namespace
0053 } // end boost namespace
0054 
0055 #endif // BOOST_COMPUTE_ALGORITHM_GENERATE_HPP