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_MAX_ELEMENT_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_MAX_ELEMENT_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/functional.hpp>
0019 #include <boost/compute/algorithm/detail/find_extrema.hpp>
0020 #include <boost/compute/type_traits/is_device_iterator.hpp>
0021 
0022 namespace boost {
0023 namespace compute {
0024 
0025 /// Returns an iterator pointing to the element in the range
0026 /// [\p first, \p last) with the maximum value.
0027 ///
0028 /// \param first first element in the input range
0029 /// \param last last element in the input range
0030 /// \param compare comparison function object which returns true if the first
0031 ///        argument is less than (i.e. is ordered before) the second.
0032 /// \param queue command queue to perform the operation
0033 ///
0034 /// For example, to find \c int2 value with maximum first component in given vector:
0035 /// \code
0036 /// // comparison function object
0037 /// BOOST_COMPUTE_FUNCTION(bool, compare_first, (const int2_ &a, const int2_ &b),
0038 /// {
0039 ///     return a.x < b.x;
0040 /// });
0041 ///
0042 /// // create vector
0043 /// boost::compute::vector<uint2_> data = ...
0044 ///
0045 /// boost::compute::vector<uint2_>::iterator max =
0046 ///     boost::compute::max_element(data.begin(), data.end(), compare_first, queue);
0047 /// \endcode
0048 ///
0049 /// Space complexity on CPUs: \Omega(1)<br>
0050 /// Space complexity on GPUs: \Omega(N)
0051 ///
0052 /// \see min_element()
0053 template<class InputIterator, class Compare>
0054 inline InputIterator
0055 max_element(InputIterator first,
0056             InputIterator last,
0057             Compare compare,
0058             command_queue &queue = system::default_queue())
0059 {
0060     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0061     return detail::find_extrema(first, last, compare, false, queue);
0062 }
0063 
0064 ///\overload
0065 template<class InputIterator>
0066 inline InputIterator
0067 max_element(InputIterator first,
0068             InputIterator last,
0069             command_queue &queue = system::default_queue())
0070 {
0071     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0072     typedef typename std::iterator_traits<InputIterator>::value_type value_type;
0073 
0074     return ::boost::compute::max_element(
0075         first, last, ::boost::compute::less<value_type>(), queue
0076     );
0077 }
0078 
0079 } // end compute namespace
0080 } // end boost namespace
0081 
0082 #endif // BOOST_COMPUTE_ALGORITHM_MAX_ELEMENT_HPP