I want to pad a tensor (B, C, H, W) by replicating itself around it. For example, the original tensor is
[[0, 1, 2], 
 [3, 4, 5],
 [6, 7, 8]].

When padding size=2, the expected results is
[[4, 5, 3, 4, 5, 3, 4],
 [7, 8, 6, 7, 8, 6, 7],
 [1, 2, 0, 1, 2, 0, 1],
 [4, 5, 3, 4, 5, 3, 4],
 [7, 8, 6, 7, 8, 6, 7],
 [1, 2, 0, 1, 2, 3, 4],
 [4, 5, 3, 4, 5, 6, 7]].

Furthermore, how can I start convolution at position (2,2) and end at (4,4)?