]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/compute/algorithm/count.hpp
bb46ee24c93cb78b4c314ea08f7b9c9dc4ec541b
[ceph.git] / ceph / src / boost / boost / compute / algorithm / count.hpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10
11 #ifndef BOOST_COMPUTE_ALGORITHM_COUNT_HPP
12 #define BOOST_COMPUTE_ALGORITHM_COUNT_HPP
13
14 #include <boost/static_assert.hpp>
15
16 #include <boost/compute/lambda.hpp>
17 #include <boost/compute/system.hpp>
18 #include <boost/compute/command_queue.hpp>
19 #include <boost/compute/algorithm/count_if.hpp>
20 #include <boost/compute/type_traits/vector_size.hpp>
21 #include <boost/compute/type_traits/is_device_iterator.hpp>
22
23 namespace boost {
24 namespace compute {
25
26 /// Returns the number of occurrences of \p value in the range
27 /// [\p first, \p last).
28 ///
29 /// Space complexity on CPUs: \Omega(1)<br>
30 /// Space complexity on GPUs: \Omega(n)
31 ///
32 /// \see count_if()
33 template<class InputIterator, class T>
34 inline size_t count(InputIterator first,
35 InputIterator last,
36 const T &value,
37 command_queue &queue = system::default_queue())
38 {
39 BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
40 typedef typename std::iterator_traits<InputIterator>::value_type value_type;
41
42 using ::boost::compute::_1;
43 using ::boost::compute::lambda::all;
44
45 if(vector_size<value_type>::value == 1){
46 return ::boost::compute::count_if(first,
47 last,
48 _1 == value,
49 queue);
50 }
51 else {
52 return ::boost::compute::count_if(first,
53 last,
54 all(_1 == value),
55 queue);
56 }
57 }
58
59 } // end compute namespace
60 } // end boost namespace
61
62 #endif // BOOST_COMPUTE_ALGORITHM_COUNT_HPP