roofline.devPublic Beta

2D Max Pooling

0EASYPracticeReport issue

Given matrix AA of shape h×wh \times w stored in row-major order and a square pooling window of side kk, produce matrix BB of shape h/k×w/k\lfloor h/k \rfloor \times \lfloor w/k \rfloor such that

Bij=max0u<k, 0v<kA(ik+u)(jk+v)B_{ij} = \max_{0 \le u < k,\ 0 \le v < k} A_{(ik + u)\,(jk + v)}

The stride equals kk so the windows do not overlap. If hh or ww is not divisible by kk, the trailing rows or columns are discarded.

Input

  • A - input matrix of shape [h][w] stored in row-major order.
  • h - the number of rows in A.
  • w - the number of columns in A.
  • kernel_size - the side length kk of the square pooling window (also the stride).

Output

  • B - pooled matrix of shape [h/k][w/k] where each cell holds the maximum value of its corresponding k×kk \times k region of A.
Open on a desktop browser to write and submit code.

Public submissions

Practice problem · every submission below is public, click to view code

No public submissions yet — be the first to submit.