Nothing serious, but there’s a small mistake in there, I’ve tried with different shapes:
n, c, h_in, w_in = 8, 3, 32, 64
h_out, w_out = 256, 128

And the results don’t match.
However if we fix the line:
# lin_indices = lin_idx_y * h_in + lin_idx_x
lin_indices = lin_idx_y * w_in + lin_idx_x