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_MINMAX_ELEMENT_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_MINMAX_ELEMENT_HPP
0013 
0014 #include <utility>
0015 
0016 #include <boost/static_assert.hpp>
0017 
0018 #include <boost/compute/system.hpp>
0019 #include <boost/compute/command_queue.hpp>
0020 #include <boost/compute/algorithm/max_element.hpp>
0021 #include <boost/compute/algorithm/min_element.hpp>
0022 #include <boost/compute/type_traits/is_device_iterator.hpp>
0023 
0024 namespace boost {
0025 namespace compute {
0026 
0027 /// Returns a pair of iterators with the first pointing to the minimum
0028 /// element and the second pointing to the maximum element in the range
0029 /// [\p first, \p last).
0030 ///
0031 /// \param first first element in the input range
0032 /// \param last last element in the input range
0033 /// \param compare comparison function object which returns true if the first
0034 ///        argument is less than (i.e. is ordered before) the second.
0035 /// \param queue command queue to perform the operation
0036 ///
0037 /// Space complexity on CPUs: \Omega(1)<br>
0038 /// Space complexity on GPUs: \Omega(N)
0039 ///
0040 /// \see max_element(), min_element()
0041 template<class InputIterator, class Compare>
0042 inline std::pair<InputIterator, InputIterator>
0043 minmax_element(InputIterator first,
0044                InputIterator last,
0045                Compare compare,
0046                command_queue &queue = system::default_queue())
0047 {
0048     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0049     if(first == last){
0050         // empty range
0051         return std::make_pair(first, first);
0052     }
0053 
0054     return std::make_pair(min_element(first, last, compare, queue),
0055                           max_element(first, last, compare, queue));
0056 }
0057 
0058 ///\overload
0059 template<class InputIterator>
0060 inline std::pair<InputIterator, InputIterator>
0061 minmax_element(InputIterator first,
0062                InputIterator last,
0063                command_queue &queue = system::default_queue())
0064 {
0065     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0066     if(first == last){
0067         // empty range
0068         return std::make_pair(first, first);
0069     }
0070 
0071     return std::make_pair(min_element(first, last, queue),
0072                           max_element(first, last, queue));
0073 }
0074 
0075 } // end compute namespace
0076 } // end boost namespace
0077 
0078 #endif // BOOST_COMPUTE_ALGORITHM_MINMAX_ELEMENT_HPP