StdDev
Calculates the standard deviation of a vector.
The calculation formula is as follows:

The function interface declaration is as follows:
- Operations on floating-point numbers:
HmppResult HMPPS_StdDev_32f(const float *src, int32_t len, float *stdDev, HmppHintAlgorithm hint);
HmppResult HMPPS_StdDev_64f(const double *src, int32_t len, double *stdDev);
- Scaling of integers:
HmppResult HMPPS_StdDev_16s_S(const int16_t *src, int32_t len, int16_t *stdDev, double scale);
HmppResult HMPPS_StdDev_16s32s_S(const int16_t *src, int32_t len, int32_t *stdDev, 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 |
stdDev |
Pointer to the standard deviation |
The value cannot be NULL. |
Output |
hint |
Algorithm policy |
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 stdDev 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 StdDevExample(void)
{
float src[BUFFER_SIZE_T] = {4.58, 0.98, 4.30, 8.03, 11.19, 8.41, 4.55, 9.90, 0.14, 9.59};
float dst;
HmppHintAlgorithm hint = HMPP_ALGHINT_NONE;
HmppResult result = HMPPS_StdDev_32f(src, BUFFER_SIZE_T, &dst, hint);
printf("stdDev: result = %d ", result);
if (result != HMPP_STS_NO_ERR) {
return;
}
printf("stdDev = %.2f\n", dst);
}
Output:
stdDev: result = 0 stdDev = 3.82