Bolt  1.1
C++ template library with support for OpenCL
Functions
Amp-counting

Functions

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

Detailed Description

Function Documentation

template<typename InputIterator , typename EqualityComparable >
bolt::amp::iterator_traits<InputIterator>::difference_type bolt::amp::count ( control &  ctl,
InputIterator  first,
InputIterator  last,
const EqualityComparable &  value 
)

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

Parameters
ctlOptional Control structure to control accelerator,debug, tuning. See bolt::amp::control.
firstBeginning of the source copy sequence.
lastEnd of the source copy sequence.
valueEquality Comparable value.
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::amp::count (A, A+14, 42);
// countOf42 contains 4.
template<typename InputIterator , typename Predicate >
bolt::amp::iterator_traits< InputIterator >::difference_type bolt::amp::count_if ( control &  ctl,
InputIterator  first,
InputIterator  last,
Predicate  predicate = bolt::amp::detail::CountIfEqual< int >() 
)

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

Parameters
ctlOptional Control structure to control accelerator,debug, tuning. See bolt::amp::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.
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) restrict(amp,cpu) {
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::amp::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.

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