◆ reduce() [2/2]

template<typename T , typename F >
T boost::simd::reduce ( T const *  first,
T const *  last,
init,
binop 
)

Reduces the range [first; last), possibly permuted and aggregated in unspecified manner, along with the initial value init over binary_op.

Note
The summation order can be different from the order of a sequential summation , thus leading to different results.
Example:
#include <boost/simd/algorithm/reduce.hpp>
#include <iostream>
#include <numeric>
int main()
{
float values[] = {1.f,2.f,3.f,4.f,5.f,6.f,7.f,8.f,9.f,};
std::cout << "SIMD reduce :"
<< boost::simd::reduce( &values[0], &values[0]+9, 1.f
)
<< std::endl;
return 0;
}
Possible output:
SIMD reduce : 285
Parameters
firstBeginning of the range of elements to sum
lastEnd of the range of elements to sum
initInitial value of the reduction
binopBinary function object that will be applied in unspecified order to the result of dereferencing the input pointers, the results of other binop and @ init.
Returns
The generalized sum of the given init value and elements in the given range over @ binop.