How to do 'same' padding in PyTorch if (n - 1) / 2 is no integer value
I am trying to reconstruct a neural network written in tensorflow. For the convolutional layer, they just use padding='SAME'. This doesn't exist in pytorch. I know, that I can calculate the padding with p = (n - 1) / 2 for stride=1. But what if this doesn't result in an integer value? In my case, n is 4 and I always want to achieve same padding.

Use math.floor function to round down to the nearest integer or the math.ceil function to round up to the nearest integer:
import math

# for flooring
p = math.floor((n - 1) / 2))

# for ceiling
p = math.ceil((n - 1) / 2))

For example, by default, pytorch uses flooring for MaxPool layers. So, I think flooring is a good starting point.
