On Monday, 18 September 2017 at 21:58:39 UTC, Alex wrote:
On Monday, 18 September 2017 at 18:49:54 UTC, ag0aep6g wrote:
Doesn't work for me. This still fails compilation with the
same error:
----
import std.algorithm.iteration : sum, cumulativeFold;
void main()
{
double[5] a;
auto asum = 1.23;
auto jProbs = a[].cumulativeFold!((a, b) => (a + b)/asum);
}
----
So, this is a bug, isn't it? I assume, I should file it then...
I have this same issue. Anyone have any thoughts on a workaround?
For example, my attempt at an exponential moving average doesn't
compile:
auto ema(Range,T) (Range rng, int period, T seed) {
return rng.cumulativeFold!((a,b) =>
a+(2.0/(period+1))*(b-a))(seed.to!double);
}
So I ended up with this:
auto ema(Range,T) (Range rng, int period, T seed) {
struct EMA(Range) {
double currentValue;
double weighting;
Range rng;
this (Range r, int p, double s) {
currentValue = s;
weighting = 2.0 / (p+1);
rng = r;
}
auto front() { return currentValue; }
auto popFront() {
rng.popFront;
if (!rng.empty){
currentValue += (rng.front -
currentValue)*weighting;
}
}
auto empty() { return rng.empty; }
}
return EMA!Range(rng,period,seed.to!double);
}
Thanks,
Jordan