Rate This Document
Findability
Accuracy
Completeness
Readability

MeanStdDev

Calculates the mean value and standard deviation of a vector. The formulas are as follows:

  • Mean value

  • Standard deviation

The function interface is declared as follows:

  • Operations on floating-point numbers:

    HmppResult HMPPS_MeanStdDev_32f(const float *src, int32_t len, float *mean, float *stdDev, HmppHintAlgorithm hint);

    HmppResult HMPPS_MeanStdDev_64f(const double *src, int32_t len, double *mean, double *stdDev);

  • Operations on integers with scaling:

    HmppResult HMPPS_MeanStdDev_16s_S(const int16_t *src, int32_t len, int16_t *mean, int16_t *stdDev, double scale);

    HmppResult HMPPS_MeanStdDev_16s32s_S(const int16_t *src, int32_t len, int32_t *mean, 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

[2, INT_MAX]

Input

mean

Pointer to the mean value

The value cannot be NULL.

Output

stdDev

Pointer to the standard deviation

The value cannot be NULL.

Output

hint

Algorithm mode (defined in the HmppHintAlgorithm enumeration type. See Enumeration Types.)

The value is an element of HmppHintAlgorithm:

  • HMPP_ALGHINT_NONE
  • HMPP_ALGHINT_FAST
  • HMPP_ALGHINT_ACCURATE

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, mean, 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 MeanStdDevExample(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;
    float stdDev;
    HmppHintAlgorithm hint = HMPP_ALGHINT_FAST;

    HmppResult result = HMPPS_MeanStdDev_32f(src, BUFFER_SIZE_T, &mean, &stdDev, hint);
    printf("result = %d\n", result);
    if (result != HMPP_STS_NO_ERR) {
        return;
    }
    printf("mean = %.3f, stdDev = %.3f\n", mean, stdDev);
}

Output:

result = 0
mean = 4.096, stdDev = 2.681