I was wondering wether there was a function in std:: (as of c++11) to compute the sum update operation (or 'rolling window sum'). Because I'm not sure how that operation is usually called (and this may be what's preventing me from finding it in std::) the last line of the small code below does what I want (and call the rolling window sum...)

const int n=101, m=n/2;
float a3[n];
float aD[m-1];
std::fill_n(array,m-1,0.0f);

for(i=0;i<n;i++)
    a3[i]=rand();
for(i=0;i<m;i++)
    aD[0]+=a3[i];                   
for(i=1;i<(m-1);i++)
    aD[i]=aD[i-1]+a3[i+m-1]-a3[i-1];  //'here: sum update of a3
有帮助吗?

解决方案

The standard library offers no such functionality. You need to implement it yourself.

其他提示

not sure if this would help you, but there's Boost.Accumulators with its rolling_sum.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top