The OpenD Programming Language

slide

Lazy convolution for tensors.

Suitable for simple convolution algorithms.

  1. auto slide(Slice!(Iterator, N, kind) slice)
    template slide(size_t params, alias fun)
    static if(params > 1 && __traits(isSame, naryFun!fun, fun))
    slide
    (
    Iterator
    size_t N
    SliceKind kind
    )
    (
    Slice!(Iterator, N, kind) slice
    )
    if (
    params <= 'z' - 'a' + 1
    )
  2. auto slide(S[] slice)
  3. auto slide(S slice)

Members

Functions

slide
auto slide(Slice!(Iterator, N, kind) slice)
auto slide(S[] slice)
auto slide(S slice)

Parameters

params

windows length.

fun

one dimensional convolution function with params arity.

Examples

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]);

See Also

Meta