Sum array elements over a given dimension, according to an array of keys. More...
Functions | |
AFAPI void | sumByKey (array &keys_out, array &vals_out, const array &keys, const array &vals, const int dim=-1) |
C++ Interface to sum array elements over a given dimension, according to an array of keys. More... | |
AFAPI void | sumByKey (array &keys_out, array &vals_out, const array &keys, const array &vals, const int dim, const double nanval) |
C++ Interface to sum array elements over a given dimension, replacing any NaNs with a specified value, according to an array of keys. More... | |
AFAPI af_err | af_sum_by_key (af_array *keys_out, af_array *vals_out, const af_array keys, const af_array vals, const int dim) |
C Interface to sum array elements over a given dimension, according to an array of keys. More... | |
AFAPI af_err | af_sum_by_key_nan (af_array *keys_out, af_array *vals_out, const af_array keys, const af_array vals, const int dim, const double nanval) |
C Interface to sum array elements over a given dimension, replacing any NaNs with a specified value, according to an array of keys. More... | |
Sum array elements over a given dimension, according to an array of keys.
The values corresponding to each group of consecutive equal keys will be summed together. Keys can repeat; however, only consecutive key values will be considered for each reduction. If a key value is repeated somewhere else in the keys array it will be considered the start of a new reduction. There are two outputs: the reduced set of consecutive keys and the corresponding final set of reduced values.
An example demonstrating the reduction behavior can be seen in the following snippet.
The keys' input type must be integer (s32 or u32).
This table defines output types for corresponding input types:
Input Type | Output Type |
---|---|
f32, f64, c32, c64 | same as input |
s32, s64, u32, u64 | same as input |
s16 | s32 |
u16, u8, b8 | u32 |
f16 | f32 |
The keys array must be 1-dimensional matching the size of the reduced dimension. An example of multi-dimensional reduce-by-key can be seen below:
AFAPI af_err af_sum_by_key | ( | af_array * | keys_out, |
af_array * | vals_out, | ||
const af_array | keys, | ||
const af_array | vals, | ||
const int | dim | ||
) |
C Interface to sum array elements over a given dimension, according to an array of keys.
[out] | keys_out | reduced keys |
[out] | vals_out | sum |
[in] | keys | keys array |
[in] | vals | input array |
[in] | dim | dimension along which the summation occurs |
AFAPI af_err af_sum_by_key_nan | ( | af_array * | keys_out, |
af_array * | vals_out, | ||
const af_array | keys, | ||
const af_array | vals, | ||
const int | dim, | ||
const double | nanval | ||
) |
C Interface to sum array elements over a given dimension, replacing any NaNs with a specified value, according to an array of keys.
[out] | keys_out | reduced keys |
[out] | vals_out | sum |
[in] | keys | keys array |
[in] | vals | input array |
[in] | dim | dimension along which the summation occurs |
[in] | nanval | value that replaces NaNs |
AFAPI void sumByKey | ( | array & | keys_out, |
array & | vals_out, | ||
const array & | keys, | ||
const array & | vals, | ||
const int | dim, | ||
const double | nanval | ||
) |
C++ Interface to sum array elements over a given dimension, replacing any NaNs with a specified value, according to an array of keys.
[out] | keys_out | reduced keys |
[out] | vals_out | sum |
[in] | keys | keys array |
[in] | vals | input array |
[in] | dim | dimension along which the summation occurs |
[in] | nanval | value that replaces NaNs |
AFAPI void sumByKey | ( | array & | keys_out, |
array & | vals_out, | ||
const array & | keys, | ||
const array & | vals, | ||
const int | dim = -1 |
||
) |
C++ Interface to sum array elements over a given dimension, according to an array of keys.
[out] | keys_out | reduced keys |
[out] | vals_out | sum |
[in] | keys | keys array |
[in] | vals | input array |
[in] | dim | dimension along which the summation occurs, -1 denotes the first non-singleton dimension |