udev
udev

Reputation: 59

Computing average of array of doubles in a vectorized way?

Given an array V of doubles the goal is to compute the average A.

The usually recommended solution is something like:

double A = V[0];
for (int i = 1; i<N; i++)
{
    A = ((A * i) + V[i]) / (i + 1.0);
}

Computing an average of an array seems to be a common operation, yet I fail to find a function that would do that in a vectorized fashion.

All I found in vDSP is the vavlinD function which computes arrays of averages, and cannot be retrofitted to compute the average of a single array.

Upvotes: 1

Views: 407

Answers (1)

udev
udev

Reputation: 59

Found the right function in vDSP. It is vDSP_meanv.

Upvotes: 2

Related Questions