maxpool2d
Builtin index · Statistics & ML
result = maxpool2d(x, size, [stride=])
Input: x, size, stride · Output: result
What it is
Downsamples an (H, W) matrix x by taking the largest value in each size x size window (integer size), moving stride positions at a time (integer, defaults to size — non-overlapping windows).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = maxpool2d(x, size, [stride=]) | x matrixnot documented yetsize matrixnot documented yetstride matrix, optionalnot documented yet | result matrix | Returns a smaller (H', W') matrix. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
x1d = [1.0, 2.0, 3.0, 4.0, 5.0]
edge_kernel = [1.0, 0.0, -1.0]
y1d = conv1d(x1d, edge_kernel)
print("conv1d edge response: {y1d}")
img = [1, 5, 2, 8; 4, 3, 9, 1; 7, 2, 6, 0; 1, 1, 1, 1]
k2d = [1, 0; 0, -1]
y2d = conv2d(img, k2d, 1, "valid")
print("conv2d output:\n{y2d}")
print("maxpool2d: {maxpool2d(img, 2)}")
print("avgpool2d: {avgpool2d(img, 2)}")
conv1d edge response: [-2, -2, -2] conv2d output: [-2, -4, 1; 2, -3, 9; 6, 1, 5] maxpool2d: [5, 9; 7, 6] avgpool2d: [3.25, 5; 2.75, 2]
from statistics-ml
How it works
maxpool2d(x, pool_size, [stride]) — 2-D max pooling, "valid" only (see maxpool2d_forward_single's own doc comment for why padding is out of scope for a max). stride defaults to pool_size (non-overlapping windows, the ordinary convention every real framework defaults to as well) when omitted. Backward routes each upstream gradient element to the exact argmax position the forward pass used — gradient-checked against central finite differences before this shipped.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.