auto data = 10.iota; auto sw = data.slide!(3, "a + 2 * b + c"); import mir.utility: max; assert(sw.length == max(0, cast(ptrdiff_t)data.length - 3 + 1)); assert(sw == sw.length.iota.map!"(a + 1) * 4"); assert(sw == [4, 8, 12, 16, 20, 24, 28, 32]);
ND-use case
auto data = [4, 5].iota; enum factor = 1.0 / 4 ^^ data.shape.length; alias scaled = a => a * factor; auto sw = data.slide!(3, "a + 2 * b + c").map!scaled; assert(sw == [4, 5].iota[1 .. $ - 1, 1 .. $ - 1]);
Lazy convolution for tensors.
Suitable for simple convolution algorithms.