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_COUNT_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_COUNT_HPP
0013 
0014 #include <boost/static_assert.hpp>
0015 
0016 #include <boost/compute/lambda.hpp>
0017 #include <boost/compute/system.hpp>
0018 #include <boost/compute/command_queue.hpp>
0019 #include <boost/compute/algorithm/count_if.hpp>
0020 #include <boost/compute/type_traits/vector_size.hpp>
0021 #include <boost/compute/type_traits/is_device_iterator.hpp>
0022 
0023 namespace boost {
0024 namespace compute {
0025 
0026 /// Returns the number of occurrences of \p value in the range
0027 /// [\p first, \p last).
0028 ///
0029 /// Space complexity on CPUs: \Omega(1)<br>
0030 /// Space complexity on GPUs: \Omega(n)
0031 ///
0032 /// \see count_if()
0033 template<class InputIterator, class T>
0034 inline size_t count(InputIterator first,
0035                     InputIterator last,
0036                     const T &value,
0037                     command_queue &queue = system::default_queue())
0038 {
0039     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0040     typedef typename std::iterator_traits<InputIterator>::value_type value_type;
0041 
0042     using ::boost::compute::_1;
0043     using ::boost::compute::lambda::all;
0044 
0045     if(vector_size<value_type>::value == 1){
0046         return ::boost::compute::count_if(first,
0047                                           last,
0048                                           _1 == value,
0049                                           queue);
0050     }
0051     else {
0052         return ::boost::compute::count_if(first,
0053                                           last,
0054                                           all(_1 == value),
0055                                           queue);
0056     }
0057 }
0058 
0059 } // end compute namespace
0060 } // end boost namespace
0061 
0062 #endif // BOOST_COMPUTE_ALGORITHM_COUNT_HPP