The C++ interface for segsum. More...

array segsum (const array &input, const array &segments, bool reduce=false)
 

Detailed Description

The C++ interface for segsum.

Segmented sum of a set of elements

Function Documentation

array af::segsum ( const array &  input,
const array &  segments,
bool  reduce = false 
)
float h_values[] = {1, 2, 3, 4, 5};
float h_keys [] = {1, 2, 2, 2, 3};
array values = array(1, 5, h_values);
array keys = array(1, 5, h_keys);
array res_scan = segsum(values, keys); // segsum(values, keys, false);
array res_sum = segsum(values, keys, true);
print(res_scan); // 1.00 2.00 5.00 9.00 5.00
print(res_sum); // 0.00 1.00 9.00 5.00 0.00

Segmented sum

Parameters
[in]inputvalues to sum (treated as vector)
[in]segmentsThe vector denoting segment number. Should be sorted.
[in]reduceSegmented operation: cumulation (false) or reduction (true)
Returns
Vector containing the
  • cumulative sums for each segment , if reduce is false
  • sum at the end of each segment, if reduce is true