Affine_grid / grid_sample for rotation in non-square inputs

In case of non-square inputs, which theta is valid?
I want to rotate around a center (x, y)
then theta is
[ [cosθ, -sinθ, x * sinθ + y * (1 - cosθ)],
[ [sinθ, cosθ, x * (1-cosθ) - y * sinθ)] ]

But in case of height and width of input is not equal, it doesn’t works.
what is valid theta ?