In addition to those possibilities, another thing to check is the ranges on your loops over h and w. There are a number of common mistakes there:
- Don’t include the stride in the range: you are looping over the output space, so you must touch every location. The striding happens in the input space.
- One other mistake is switching the meaning of h and w. Remember that h stands for “height” not “horizontal”.
Here’s a thread which lays out the algorithm here in words that is definitely worth a look.