Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2014 Roshan <thisisroshansmail@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_ROTATE_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_ROTATE_HPP
0013 
0014 #include <boost/compute/system.hpp>
0015 #include <boost/compute/algorithm/copy.hpp>
0016 #include <boost/compute/container/vector.hpp>
0017 
0018 namespace boost {
0019 namespace compute {
0020 
0021 /// Performs left rotation such that element at \p n_first comes to the
0022 /// beginning.
0023 ///
0024 /// Space complexity: \Omega(distance(\p first, \p last))
0025 ///
0026 /// \see rotate_copy()
0027 template<class InputIterator>
0028 inline void rotate(InputIterator first,
0029                    InputIterator n_first,
0030                    InputIterator last,
0031                    command_queue &queue = system::default_queue())
0032 {
0033     //Handle trivial cases
0034     if (n_first==first || n_first==last)
0035     {
0036         return;
0037     }
0038 
0039     //Handle others
0040     typedef typename std::iterator_traits<InputIterator>::value_type T;
0041 
0042     size_t count = detail::iterator_range_size(first, n_first);
0043     size_t count2 = detail::iterator_range_size(first, last);
0044 
0045     const context &context = queue.get_context();
0046     vector<T> temp(count2, context);
0047     ::boost::compute::copy(first, last, temp.begin(), queue);
0048 
0049     ::boost::compute::copy(temp.begin()+count, temp.end(), first, queue);
0050     ::boost::compute::copy(temp.begin(), temp.begin()+count, last-count, queue);
0051 }
0052 
0053 } //end compute namespace
0054 } //end boost namespace
0055 
0056 #endif // BOOST_COMPUTE_ALGORITHM_ROTATE_HPP