Evaluate the cumulative sum (inclusive) along a given dimension. More...
Functions | |
AFAPI array | accum (const array &in, const int dim=0) |
C++ Interface to evaluate the cumulative sum (inclusive) along a given dimension. More... | |
AFAPI af_err | af_accum (af_array *out, const af_array in, const int dim) |
C Interface to evaluate the cumulative sum (inclusive) along a given dimension. More... | |
Evaluate the cumulative sum (inclusive) along a given dimension.
For a 1D array \(X\), the inclusive cumulative sum calculates \(x_i = \sum_{p=0}^{i}x_p\) for every \(x \in X\). Here is a simple example for the 1D case:
For 2D arrays and higher dimensions, you can specify the dimension along which the cumulative sum will be calculated. Thus, the formula above will be calculated for all array slices along the specified dimension (in the 2D case for example, this looks like \(x_{i,j} = \sum_{p=0}^{j}x_{i,p}\) if the second dimension (dim1) was chosen). If no dimension is specified, then the first dimension (dim0) is used by default (only in the C++ API; the dimension is required to be specified in the C API):
The output array type may be different from the input array type. The following table defines corresponding output types for each input type:
Input Type | Output Type |
---|---|
f32, f64, c32, c64 | same as input |
s32, s64, u32, u64 | same as input |
s16 | s32 |
u16, u8, b8 | u32 |
This function runs across all batches in the input simultaneously.
C++ Interface to evaluate the cumulative sum (inclusive) along a given dimension.
[in] | in | input array |
[in] | dim | dimension along which the sum is accumulated, 0 denotes the first non-singleton dimension |
C Interface to evaluate the cumulative sum (inclusive) along a given dimension.
[out] | out | cumulative sum |
[in] | in | input array |
[in] | dim | dimension along which the sum is accumulated |