Mean
Calculates the average value of a vector.
The function interface declaration is as follows:
- Operations on floating-point numbers:
HmppResult HMPPS_Mean_32f(const float *src, int32_t len, float *mean, HmppHintAlgorithm hint);
HmppResult HMPPS_Mean_64f(const double *src, int32_t len, double *mean);
HmppResult HMPPS_Mean_32fc(const Hmpp32fc *src, int32_t len, Hmpp32fc *mean, HmppHintAlgorithm hint);
HmppResult HMPPS_Mean_64fc(const Hmpp64fc *src, int32_t len, Hmpp64fc *mean);
- Operations on integers with scaling:
HmppResult HMPPS_Mean_16s_S(const int16_t *src, int32_t len, int16_t *mean, double scale);
HmppResult HMPPS_Mean_32s_S(const int32_t *src, int32_t len, int32_t *mean, double scale);
HmppResult HMPPS_Mean_16sc_S(const Hmpp16sc *src, int32_t len, Hmpp16sc *mean, 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 |
mean |
Pointer to the average value |
The value cannot be NULL. |
Output |
hint |
Algorithm mode |
HmppAlgHintNone, HmppAlgHintFast, HmppAlgHintAccurate |
Input |
scale |
Scale factor |
scale = 2^n, where n is an integer. The value is within (0, INF). |
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 mean 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 MeanExample(void)
{
float src[BUFFER_SIZE_T] = {3.45, 0.12, 7.77, 4.45, 2.44, 3.67, 2.78, 8.88, 1.83, 5.57};
float mean;
HmppHintAlgorithm hint = HMPP_ALGHINT_FAST;
HmppResult result = HMPPS_Mean_32f(src, BUFFER_SIZE_T, &mean, hint);
printf("result = %d ", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
printf("mean = %.3f\n", mean);
}
Output:
result = 0 mean = 4.096