Mean
The function interface is declared as follows:
HmppResult HMPPS_AggMean_16s(const int16_t *src, int32_t len, int8_t *nullAddr, bool *overflow, double *sum, int64_t *count);
HmppResult HMPPS_AggMean_32s(const int32_t *src, int32_t len, int8_t *nullAddr, bool *overflow, double *sum, int64_t *count);
HmppResult HMPPS_AggMean_64s(const int64_t *src, int32_t len, int8_t *nullAddr, bool *overflow, double *sum, int64_t *count);
HmppResult HMPPS_AggMean_64f(const double *src, int32_t len, int8_t *nullAddr, bool *overflow, double *sum, int64_t *count);
HmppResult HMPPS_AggMean_decimal64(const int64_t *src, int32_t len, int8_t *nullAddr, bool *overflow, HmppDecimal128 *sum, int64_t *count);
HmppResult HMPPS_AggMean_decimal128(const HmppDecimal128 *src, int32_t len, int8_t *nullAddr, bool *overflow, HmppDecimal128 *sum, int64_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 |
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, nullAddr, 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 <stdint.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;
int64_t count;
bool overflow;
HmppResult result = HMPPS_AggMean_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.000000, count = 7, overflow = 0