AvgPool

Undocumented in source.
alias AvgPool(T, size_t poolDims) = Pool!(false, T, poolDims)

Examples

import std.stdio;
import mir.ndslice;
import numir;

auto f = MaxPool!(float, 2)([3, 3], [1, 1], [1, 1]);
auto x = iota(2, 2, 1, 3).as!float.slice.variable;
// [[[[0, 1, 2]], [[3, 4, 5]]],
//  [[[6, 7, 8]], [[9, 10, 11]]]]
enum yex = [[[[1, 2, 2]], [[4, 5, 5]]], [[[7, 8, 8]], [[10, 11, 11]]]];

// mir implementation
auto hy = f.forward(x);
assert(hy.sliced == yex);

version (grain_cuda) {
    auto y = f.forward(x.to!DeviceStorage);
    assert(y.to!HostStorage.sliced == yex);
    auto gx = f.backward(y);
    enum gxex = [[[[0, 1, 4]], [[0, 4, 10]]], [[[0, 7, 16]], [[0, 10, 22]]]];
    assert(gx.to!HostStorage.sliced == gxex);
}

Meta