![]() |
|
Cumulative sum (inclusive). More...
Functions | |
AFAPI array | accum (const array &in, const int dim=0) |
C++ Interface for computing the cumulative sum (inclusive) of an array. More... | |
AFAPI af_err | af_accum (af_array *out, const af_array in, const int dim) |
C Interface for computing the cumulative sum (inclusive) of an array. More... | |
Cumulative sum (inclusive).
Also known as a scan
Calculate the cumulative sum (inclusive) along the specified 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 the corresponding output types for each input type:
Input Type | Output Type |
---|---|
f32, f64, c32, c64 | same as input |
s32, u32, s64, u64 | same as input |
s16 | s32 |
u16, u8, b8 | u32 |
This function performs the operation across all batches present in the input simultaneously.
C++ Interface for computing the cumulative sum (inclusive) of an array.
[in] | in | is the input array |
[in] | dim | is the dimension along which the inclusive sum is calculated |
C Interface for computing the cumulative sum (inclusive) of an array.
[out] | out | will contain inclusive sums of the input |
[in] | in | is the input array |
[in] | dim | is the dimension along which the inclusive sum is calculated |