Back to home page

EIC code displayed by LXR

 
 

    


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

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_UNIQUE_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_UNIQUE_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/unique_copy.hpp>
0019 #include <boost/compute/container/vector.hpp>
0020 #include <boost/compute/functional/operator.hpp>
0021 #include <boost/compute/type_traits/is_device_iterator.hpp>
0022 
0023 namespace boost {
0024 namespace compute {
0025 
0026 /// Removes all consecutive duplicate elements (determined by \p op) from the
0027 /// range [first, last). If \p op is not provided, the equality operator is
0028 /// used.
0029 ///
0030 /// \param first first element in the input range
0031 /// \param last last element in the input range
0032 /// \param op binary operator used to check for uniqueness
0033 /// \param queue command queue to perform the operation
0034 ///
0035 /// \return \c InputIterator to the new logical end of the range
0036 ///
0037 /// Space complexity: \Omega(4n)
0038 ///
0039 /// \see unique_copy()
0040 template<class InputIterator, class BinaryPredicate>
0041 inline InputIterator unique(InputIterator first,
0042                             InputIterator last,
0043                             BinaryPredicate op,
0044                             command_queue &queue = system::default_queue())
0045 {
0046     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0047     typedef typename std::iterator_traits<InputIterator>::value_type value_type;
0048 
0049     vector<value_type> temp(first, last, queue);
0050 
0051     return ::boost::compute::unique_copy(
0052         temp.begin(), temp.end(), first, op, queue
0053     );
0054 }
0055 
0056 /// \overload
0057 template<class InputIterator>
0058 inline InputIterator unique(InputIterator first,
0059                             InputIterator last,
0060                             command_queue &queue = system::default_queue())
0061 {
0062     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0063     typedef typename std::iterator_traits<InputIterator>::value_type value_type;
0064 
0065     return ::boost::compute::unique(
0066         first, last, ::boost::compute::equal_to<value_type>(), queue
0067     );
0068 }
0069 
0070 } // end compute namespace
0071 } // end boost namespace
0072 
0073 #endif // BOOST_COMPUTE_ALGORITHM_UNIQUE_HPP