01-convolutions/03-stride showed one way to shrink a feature map: skip positions while still running the full weighted-sum computation at each one. Pooling is a second, even simpler way — instead of a learned weighted sum, just look at a small window and keep the single strongest value in it, throwing the rest away entirely.
The intuition is that a feature map's job is usually to say "how strongly does this pattern show up here" — if it fired strongly ANYWHERE in a small neighborhood, that's usually the information worth keeping, and exactly where within that neighborhood it fired is often noise you can safely discard.
Theory says: divide the image into small windows (non-overlapping by default), and for each window, keep only its maximum value, once per channel.
Implement max_pool2d(image, kernel_size, stride=None) against that reasoning.
image: shape (C, H, W).kernel_size: the pooling window's height and width.stride: step between windows; if None, defaults to kernel_size (non-overlapping pooling).(C, (H - kernel_size)//stride + 1, (W - kernel_size)//stride + 1).image is never modified in place.Open one at a time. Each gives away a little more than the last.
This is the same sliding-window structure as 01-convolutions — the only thing that changes is what you do with the window: .max() instead of elementwise-multiply-and-sum.
Pool each channel independently: window.max(axis=(1, 2)) on a (C, kernel_size, kernel_size) slice reduces over just the spatial axes, leaving one max per channel in a single call.
No results yet
Run your code to check it against the examples, or submit to run every test.