Pooling
Spatial reduction and gradient distribution.
From the implementationinclude/nexus_model/layers/pooling.hpp
01MaxPool2D#
MaxPool2D(kernel,stride=-1,padding=0). Negative default stride becomes the kernel size. Requires rank-4 NCHW. First maximum wins; forward stores argmax. Backward scatter-adds to winning cells.
MaxPool2D pool(2);auto x=Tensor::zeros({8,32,28,28});auto y=pool.forward(x); // [8,32,14,14]02AvgPool2D#
AvgPool2D(kernel,stride=-1,padding=0,count_include_pad=true). The default denominator includes padding. With false, only valid cells count. Backward distributes gradients with the same denominator and sums overlaps.
03GlobalAvgPool2D#
GlobalAvgPool2D() averages H×W per channel. Output is directly [N,C]; no extra Flatten is needed. Every cell receives gradient scaled by 1/(HW).
◆Read alongside the source. API behavior reflects the current implementation.