Do more. Code less. Free software for GPU computing.
<scroll to top>

Sum and product

Data Analysis

array sum (const array &input, int dim=-1)
 sum of the elements along a dimension in matrix
template<typename ty >
ty sum (const array &input)
 summation of all elements in array
array prod (const array &input, int dim=-1)
 product (multiplication) of elements along a dimension in matrix
template<typename ty >
ty prod (const array &input)
 product (multiplication) of all elements in array

Function Documentation

array af::sum ( const array &  input,
int  dim = -1 
)

sum of the elements along a dimension in matrix

Parameters:
[in]input
[in]dimdimension along which to operate (-1 indicates first nonsingleton dimension)
Returns:
array with values summed along the dimension dim in the input
Examples:
examples/misc/gfor.cpp, and examples/misc/integer.cpp.
ty af::sum ( const array &  input)

summation of all elements in array

       float hx[] = { -3, -5, 2, -9 };
       array x1(hx, 2,2); // 2x2 matrix
       array x2(hx, 4,1); // 4x1 vector
       printf("%g,%g\n", sum<float>(x1), sum<float>(x2)); // -15,-15
Parameters:
[in]input
Returns:
sum of all values in the input array
array af::prod ( const array &  input,
int  dim = -1 
)

product (multiplication) of elements along a dimension in matrix

Parameters:
[in]input
[in]dimdimension along which to operate (-1 indicates first nonsingleton dimension)
Returns:
array with values multiplied along the dimension dim in the input
Examples:
examples/misc/integer.cpp.
ty af::prod ( const array &  input)

product (multiplication) of all elements in array

       float hx[] = { -3, -5, 2, -9 };
       array x1(hx, 2,2); // 2x2 matrix
       array x2(hx, 4,1); // 4x1 vector
       printf("%g,%g\n", prod<float>(x1), prod<float>(x2)); // -270,-270
Parameters:
[in]input
Returns:
product of all values in the input array
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines