Extracting indexes from a max pool over uniform data
I'm trying to find max points in a 2D tensor for a given kernel size, but I'm having issues with a special case where all the values are uniform. For example, given the following example, I would like to mark each point as a max point:

+---+---+---+---+
| 5 | 5 | 5 | 5 |
+---+---+---+---+
| 5 | 5 | 5 | 5 |
+---+---+---+---+
| 5 | 5 | 5 | 5 |
+---+---+---+---+
| 5 | 5 | 5 | 5 |
+---+---+---+---+


If I run torch.nn.functional.max_pool2d with a kernel size=3, stride=1, and padding=1, I get the following indicies:

+---+---+---+----+
| 0 | 0 | 1 |  2 |
+---+---+---+----+
| 0 | 0 | 1 |  2 |
+---+---+---+----+
| 4 | 4 | 5 |  6 |
+---+---+---+----+
| 8 | 8 | 9 | 10 |
+---+---+---+----+


What changes do I need to account for to instead obtain the following indicies?

+----+----+----+----+
| 1  | 2  | 3  |  4 |
+----+----+----+----+
|  5 |  6 |  7 |  8 |
+----+----+----+----+
|  9 | 10 | 11 | 12 |
+----+----+----+----+
| 13 | 14 | 15 | 16 |
+----+----+----+----+


You can do the following:

a = torch.ones(4,4)
indices = (a == torch.max(a).item()).nonzero()


What this does is return a [16,2] sized tensor with the 2D coordinates of the max value(s), i.e. [0,0], [0,1], .., [3,3]. The torch.max part should be easy to understand, nonzero() considers the boolean tensor given by (a == torch.max(a).item()), takes False to be 0, and returns the non-zero indices. Hope this helps!
