Cumulative sum (inclusive). Also known as a scan. 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...

## Detailed Description

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:

float hA[] = {0, 1, 2, 3, 4};
array A(5, hA);
// 0.
// 1.
// 2.
// 3.
// 4.
array accumA = accum(A);
// 0.
// 1.
// 3.
// 6.
// 10.

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):

float hB[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
array B(3, 3, hB);
// 0. 3. 6.
// 1. 4. 7.
// 2. 5. 8.
array accumB_dim0 = accum(B);
// 0. 3. 6.
// 1. 7. 13.
// 3. 12. 21.
array accumB_dim1 = accum(B, 1);
// 0. 3. 9.
// 1. 5. 12.
// 2. 7. 15.

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.

## ◆ accum()

 AFAPI array af::accum ( const array & in, const int dim = 0 )

C++ Interface for computing the cumulative sum (inclusive) of an array.

Parameters
 [in] in is the input array [in] dim is the dimension along which the inclusive sum is calculated
Returns
the output containing inclusive sums of the input
Examples
image_processing/binary_thresholding.cpp.

## ◆ af_accum()

 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.

Parameters
 [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
Returns
AF_SUCCESS if the execution completes properly
af::accum
AFAPI array accum(const array &in, const int dim=0)
C++ Interface for computing the cumulative sum (inclusive) of an array.
afcl::array
static af::array array(af::dim4 idims, cl_mem buf, af::dtype type, bool retain=false)
Create an af::array object from an OpenCL cl_mem buffer.
Definition: opencl.h:327