Bolt  1.3
C++ template library with support for OpenCL
Functions
CL-counting

Functions

template<typename InputIterator , typename Predicate >
bolt::cl::iterator_traits
< InputIterator >
::difference_type 
bolt::cl::count_if (control &ctl, InputIterator first, InputIterator last, Predicate predicate=bolt::cl::detail::CountIfEqual< int >(), const std::string &cl_code="")
 count_if counts the number of elements in the specified range for which the specified predicate is true.
 
template<typename InputIterator , typename Predicate >
bolt::cl::iterator_traits
< InputIterator >
::difference_type 
bolt::cl::count_if (InputIterator first, InputIterator last, Predicate predicate, const std::string &cl_code="")
 
template<typename InputIterator , typename EqualityComparable >
bolt::cl::iterator_traits
< InputIterator >
::difference_type 
bolt::cl::count (control &ctl, InputIterator first, InputIterator last, const EqualityComparable &value, const std::string &cl_code="")
 count counts the number of elements in the specified range which compare equal to the specified value.
 
template<typename InputIterator , typename EqualityComparable >
bolt::cl::iterator_traits
< InputIterator >
::difference_type 
bolt::cl::count (InputIterator first, InputIterator last, const EqualityComparable &value, const std::string &cl_code="")
 

Detailed Description

Function Documentation

template<typename InputIterator , typename EqualityComparable >
bolt::cl::iterator_traits<InputIterator>::difference_type bolt::cl::count ( control &  ctl,
InputIterator  first,
InputIterator  last,
const EqualityComparable &  value,
const std::string &  cl_code = "" 
)

count counts the number of elements in the specified range which compare equal to the specified value.

Parameters
ctlOptional Control structure to control command-queue, debug, tuning,etc. See bolt::cl::control
firstBeginning of the source copy sequence.
lastEnd of the source copy sequence.
valueEquality Comparable value.
cl_codeOptional OpenCL(TM) code to be prepended to any OpenCL kernels used by this function.
Returns
Count of the number of occurrences of value.
Template Parameters
InputIteratoris a model of InputIterator

Example:

int a[14] = {0, 10, 42, 55, 13, 13, 42, 19, 42, 11, 42, 99, 13, 77};
size_t countOf42 = bolt::cl::count (A, A+14, 42);
// countOf42 contains 4.
template<typename InputIterator , typename Predicate >
bolt::cl::iterator_traits< InputIterator >::difference_type bolt::cl::count_if ( control &  ctl,
InputIterator  first,
InputIterator  last,
Predicate  predicate = bolt::cl::detail::CountIfEqual< int >(),
const std::string &  cl_code = "" 
)

count_if counts the number of elements in the specified range for which the specified predicate is true.

Parameters
ctlOptional Control structure to control command-queue, debug, tuning,etc. See bolt::cl::control
firstThe first position in the sequence to be counted.
lastThe last position in the sequence to be counted.
predicateThe count is incremented for each element which returns true when passed to the predicate function.
cl_codeOptional OpenCL(TM) code to be prepended to any OpenCL kernels used by this function.
Returns
: The number of elements for which predicate is true.
Template Parameters
InputIteratoris a model of InputIterator
OutputIteratoris a model of OutputIterator

This example returns the number of elements in the range 1-60.

//Bolt functor specialized for int type.
template<typename T>
// Functor for range checking.
struct InRange {
InRange (T low, T high) {
_low=low;
_high=high;
};
bool operator() (const T& value) {
return (value >= _low) && (value <= _high) ;
};
T _low;
T _high;
};
);
int a[14] = {0, 10, 42, 55, 13, 13, 42, 19, 42, 11, 42, 99, 13, 77};
int boltCount = bolt::cl::count_if (a, a+14, InRange<int>(1,60)) ;
// boltCount 11 in range 1-60.

Example to show how to use UDD type for count_if.

struct UDD {
int a;
int b;
bool operator() (const int &x) {
return (x == a || x == b);
}
UDD()
: a(0),b(0) { }
UDD(int _in)
: a(_in), b(_in +1) { }
};
);
BOLT_TEMPLATE_REGISTER_NEW_TYPE( bolt::cl::detail::CountIfEqual, int, UDD );
std::vector<UDD> boltInput(SIZE);
UDD myUDD;
myUDD.a = 3;
myUDD.b = 5;
// Initialize boltInput
size_t boltCount = bolt::cl::count(boltInput.begin(), boltInput.end(), myUDD);