avgpool2d
Builtin index · Statistics & ML
result = avgpool2d(x, size, [stride=])
Input: x, size, stride · Output: result
What it is
Downsamples an (H, W) matrix x the same way as maxpool2d — size x size windows, stride defaulting to size — but takes the mean of each window instead of the max.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = avgpool2d(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
avgpool2d(x, pool_size, [stride]) — 2-D average pooling, "valid" only, stride defaulting to pool_size the same way maxpool2d does. Backward divides each upstream gradient element evenly across its whole pooling window.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.