Sum
Calculates the sum of all elements in a vector. The calculation formula is:
.
The function interface declaration is as follows:
- Operations on floating-point numbers:
HmppResult HMPPS_Sum_32f(const float *src, int32_t len, float *sum, HmppHintAlgorithm hint);
HmppResult HMPPS_Sum_64f(const double *src, int32_t len, double *sum);
HmppResult HMPPS_Sum_32fc(const Hmpp32fc *src, int32_t len, Hmpp32fc *sum, HmppHintAlgorithm hint);
HmppResult HMPPS_Sum_64fc(const Hmpp64fc *src, int32_t len, Hmpp64fc *sum);
- Scaling of integers:
HmppResult HMPPS_Sum_16s_S(const int16_t *src, int32_t len, int16_t *sum, double scale);
HmppResult HMPPS_Sum_32s_S(const int32_t *src, int32_t len, int32_t *sum, double scale);
HmppResult HMPPS_Sum_16s32s_S(const int16_t *src, int32_t len, int32_t *sum, double scale);
HmppResult HMPPS_Sum_16sc_S(const Hmpp16sc *src, int32_t len, Hmpp16sc *sum, double scale);
HmppResult HMPPS_Sum_16sc32sc_S(const Hmpp16sc *src, int32_t len, Hmpp32sc *sum, double scale);
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Pointer to the source vector |
The value cannot be NULL. |
Input |
len |
Vector length |
(0, INT_MAX] |
Input |
sum |
Pointer to the sum |
The value cannot be NULL. |
Output |
scale |
Scale factor |
scale = 2^n, where n is an integer. The value is within (0, INF). |
Input |
hint |
Algorithm policy |
HmppAlgHintNone, HmppAlgHintFast, HmppAlgHintAccurate |
Input |
Return Value
- Success: HMPP_STS_NO_ERR
- Failure: An error code is returned.
Error Codes
Error Code |
Description |
|---|---|
HMPP_STS_NULL_PTR_ERR |
The value of src or sum is NULL. |
HMPP_STS_SIZE_ERR |
The value of len is less than or equal to 0. |
HMPP_STS_SCALE_ERR |
The value of scale is not within the range (0, INF) or is NaN. |
Example
#define BUFFER_SIZE_T 10
void SumExample(void)
{
float src[BUFFER_SIZE_T] = {9.99, 5.42, 10.58, 5.20, 9.12, 0.86, 10.13, 5.94, -0.62, 9.19};
float sum;
HmppHintAlgorithm hint = HMPP_ALGHINT_NONE;
HmppResult result = HMPPS_Sum_32f(src, BUFFER_SIZE_T, &sum, hint);
printf("sum: result = %d ", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
printf("sum = %.2f\n", sum);
}
Output:
sum: result = 0 sum = 65.81