A high-performance general-purpose compute library

Find the sum of values in the input. More...

Functions

AFAPI array sum (const array &in, const int dim=-1)
 C++ Interface for sum of elements in an array.
 
AFAPI array sum (const array &in, const int dim, const double nanval)
 C++ Interface for sum of elements in an array while replacing nan values.
 
template<typename T >
sum (const array &in)
 C++ Interface for sum of all elements in an array.
 
template<typename T >
sum (const array &in, double nanval)
 C++ Interface for sum of all elements in an array while replacing nan values.
 
AFAPI af_err af_sum (af_array *out, const af_array in, const int dim)
 C Interface for sum of elements in an array.
 
AFAPI af_err af_sum_nan (af_array *out, const af_array in, const int dim, const double nanval)
 C Interface for sum of elements in an array while replacing nans.
 
AFAPI af_err af_sum_all (double *real, double *imag, const af_array in)
 C Interface for sum of all elements in an array.
 
AFAPI af_err af_sum_nan_all (double *real, double *imag, const af_array in, const double nanval)
 C Interface for sum of all elements in an array while replacing nans.
 

Detailed Description

Find the sum of values in the input.

This table defines the return value types for the corresponding input types

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.

Function Documentation

◆ af_sum()

AFAPI af_err af_sum ( af_array out,
const af_array  in,
const int  dim 
)

C Interface for sum of elements in an array.

Parameters
[out]outwill contain the sum of all values in in along dim
[in]inis the input array
[in]dimThe dimension along which the add operation occurs
Returns
AF_SUCCESS if the execution completes properly

◆ af_sum_all()

AFAPI af_err af_sum_all ( double *  real,
double *  imag,
const af_array  in 
)

C Interface for sum of all elements in an array.

Parameters
[out]realwill contain the real part of adding all elements in input in
[out]imagwill contain the imaginary part of adding all elements in input in
[in]inis the input array
Returns
AF_SUCCESS if the execution completes properly
Note
imag is always set to 0 when in is real

◆ af_sum_nan()

AFAPI af_err af_sum_nan ( af_array out,
const af_array  in,
const int  dim,
const double  nanval 
)

C Interface for sum of elements in an array while replacing nans.

Parameters
[out]outwill contain the sum of all values in in along dim
[in]inis the input array
[in]dimThe dimension along which the add operation occurs
[in]nanvalThe value that will replace the NaNs in in
Returns
AF_SUCCESS if the execution completes properly

◆ af_sum_nan_all()

AFAPI af_err af_sum_nan_all ( double *  real,
double *  imag,
const af_array  in,
const double  nanval 
)

C Interface for sum of all elements in an array while replacing nans.

Parameters
[out]realwill contain the real part of adding all elements in input in
[out]imagwill contain the imaginary part of adding all elements in input in
[in]inis the input array
[in]nanvalis the value which replaces nan
Returns
AF_SUCCESS if the execution completes properly
Note
imag is always set to 0 when in is real

◆ sum() [1/4]

T sum ( const array in)

C++ Interface for sum of all elements in an array.

Parameters
[in]inis the input array
Returns
the sum of all values of in

◆ sum() [2/4]

AFAPI array sum ( const array in,
const int  dim,
const double  nanval 
)

C++ Interface for sum of elements in an array while replacing nan values.

Parameters
[in]inis the input array
[in]dimThe dimension along which the add operation occurs
[in]nanvalThe value that will replace the NaNs in in
Returns
result of sum all values along dimension dim

◆ sum() [3/4]

AFAPI array sum ( const array in,
const int  dim = -1 
)

C++ Interface for sum of elements in an array.

Parameters
[in]inis the input array
[in]dimThe dimension along which the add operation occurs
Returns
result of sum all values along dimension dim
Note
dim is -1 by default. -1 denotes the first non-singleton dimension.

◆ sum() [4/4]

T sum ( const array in,
double  nanval 
)

C++ Interface for sum of all elements in an array while replacing nan values.

Parameters
[in]inis the input array
[in]nanvalThe value that will replace the NaNs in in
Returns
the sum of all values of in