Mean
The function interface declaration is as follows:
- Directly obtaining the mean value:
HmppResult HMPPS_Mean_16s(const int16_t *src, int32_t len, int16_t *mean);
HmppResult HMPPS_Mean_32s(const int32_t *src, int32_t len, int32_t *mean);
- Obtaining the sum and the number of elements used for calculation:
HmppResult HMPPS_Mean_64s(const int64_t *src, int32_t len, int8_t *nullAddr, bool *overflow, double *sum, int32_t *count);
HmppResult HMPPS_Mean_decimal128(const HmppDecimal128 *src, int32_t len, int8_t *nullAddr, bool *overflow, HmppDecimal128 *sum, int32_t *count);
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 |
mean |
Pointer to the result mean value |
The value cannot be NULL. |
Output |
nullAddr |
Pointer to a null address.
|
This field can be NULL. |
Input |
overflow |
Pointer to the overflow flag bit |
The value cannot be NULL. |
Output |
sum |
Pointer to the sum result |
The value cannot be NULL. |
Output |
count |
Pointer to the number of elements used for calculation. The final mean value is sum/count. |
The value cannot be NULL. |
Output |
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, mean, sum, count, or overflow is NULL. |
HMPP_STS_SIZE_ERR |
The value of len is less than or equal to 0. |
Example
#include <stdio.h>
#include "hmpp.h"
#define BUFFER_SIZE_T 10
int main()
{
int64_t src[BUFFER_SIZE_T] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int8_t nullAddr[BUFFER_SIZE_T] = {0, 0, 1, 1, 0, 1, 0, 0, 0, 0};
double sum;
int32_t count;
bool overflow;
HmppResult result = HMPPS_Mean_64s(src, BUFFER_SIZE_T, nullAddr, &overflow, &sum, &count);
printf("result = %d ", result);
if (result != HMPP_STS_NO_ERR) {
return 0;
}
printf("sum = %lf, count = %d, overflow = %d\n", sum, count, overflow);
}
Output:
result = 0 sum = 42, count = 7, overflow = 0