A high-performance general-purpose compute library

Sum array elements over a given dimension. More...

Functions

AFAPI array sum (const array &in, const int dim=-1)
 C++ Interface to sum array elements over a given dimension. More...
 
AFAPI array sum (const array &in, const int dim, const double nanval)
 C++ Interface to sum array elements over a given dimension, replacing any NaNs with a specified value. More...
 
template<typename T >
sum (const array &in)
 C++ Interface to sum array elements over all dimensions. More...
 
template<typename T >
sum (const array &in, double nanval)
 C++ Interface to sum array elements over all dimensions, replacing any NaNs with a specified value. More...
 
AFAPI af_err af_sum (af_array *out, const af_array in, const int dim)
 C Interface to sum array elements over a given dimension. More...
 
AFAPI af_err af_sum_all_array (af_array *out, const af_array in)
 C Interface to sum array elements over all dimensions. More...
 
AFAPI af_err af_sum_nan (af_array *out, const af_array in, const int dim, const double nanval)
 C Interface to sum array elements over a given dimension, replacing any NaNs with a specified value. More...
 
AFAPI af_err af_sum_nan_all_array (af_array *out, const af_array in, const double nanval)
 C Interface to sum array elements over all dimensions, replacing any NaNs with a specified value. More...
 
AFAPI af_err af_sum_all (double *real, double *imag, const af_array in)
 C Interface to sum array elements over all dimensions. More...
 
AFAPI af_err af_sum_nan_all (double *real, double *imag, const af_array in, const double nanval)
 C Interface to sum array elements over all dimensions, replacing any NaNs with a specified value. More...
 

Detailed Description

Sum array elements over a given dimension.

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

This function runs across all batches 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 to sum array elements over a given dimension.

Parameters
[out]outsum
[in]ininput array
[in]dimdimension along which the summation occurs
Returns
AF_SUCCESS, if function returns successfully, else an af_err code is given

◆ af_sum_all()

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

C Interface to sum array elements over all dimensions.

If in is real, imag will be set to zeros.

Parameters
[out]realsum of all real components
[out]imagsum of all imaginary components
[in]ininput array
Returns
AF_SUCCESS, if function returns successfully, else an af_err code is given

◆ af_sum_all_array()

AFAPI af_err af_sum_all_array ( af_array out,
const af_array  in 
)

C Interface to sum array elements over all dimensions.

Results in a single element af::array.

Parameters
[out]outsum
[in]ininput array
Returns
AF_SUCCESS, if function returns successfully, else an af_err code is given

◆ af_sum_nan()

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

C Interface to sum array elements over a given dimension, replacing any NaNs with a specified value.

Parameters
[out]outsum
[in]ininput array
[in]dimdimension along which the summation occurs
[in]nanvalvalue that replaces NaNs
Returns
AF_SUCCESS, if function returns successfully, else an af_err code is given

◆ af_sum_nan_all()

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

C Interface to sum array elements over all dimensions, replacing any NaNs with a specified value.

If in is real, imag will be set to zeros.

Parameters
[out]realsum of all real components
[out]imagsum of all imaginary components
[in]ininput array
[in]nanvalvalue that replaces NaNs
Returns
AF_SUCCESS, if function returns successfully, else an af_err code is given

◆ af_sum_nan_all_array()

AFAPI af_err af_sum_nan_all_array ( af_array out,
const af_array  in,
const double  nanval 
)

C Interface to sum array elements over all dimensions, replacing any NaNs with a specified value.

Results in a single element af::array.

Parameters
[out]outsum
[in]ininput array
[in]nanvalvalue that replaces NaNs
Returns
AF_SUCCESS, if function returns successfully, else an af_err code is given

◆ sum() [1/4]

T sum ( const array in)

C++ Interface to sum array elements over all dimensions.

Results in a single value as an output, which may be a single element af::array.

Parameters
[in]ininput array
Returns
sum

◆ sum() [2/4]

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

C++ Interface to sum array elements over a given dimension, replacing any NaNs with a specified value.

Parameters
[in]ininput array
[in]dimdimension along which the summation occurs
[in]nanvalvalue that replaces NaNs
Returns
sum

◆ sum() [3/4]

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

C++ Interface to sum array elements over a given dimension.

Parameters
[in]ininput array
[in]dimdimension along which the summation occurs, -1 denotes the first non-singleton dimension
Returns
sum

◆ sum() [4/4]

T sum ( const array in,
double  nanval 
)

C++ Interface to sum array elements over all dimensions, replacing any NaNs with a specified value.

Results in a single value as an output, which may be a single element af::array.

Parameters
[in]ininput array
[in]nanvalvalue that replaces NaNs
Returns
sum