I have something that looks like this...
import torch
X = torch.cat([torch.ones((2,4)).unsqueeze(0), torch.ones((2,4)).unsqueeze(0)*2, torch.ones((2,4)).unsqueeze(0)*3, torch.ones((2,4)).unsqueeze(0)*4]).unsqueeze(0)
which is
tensor([[[[1., 1., 1., 1.],
[1., 1., 1., 1.]],
[[2., 2., 2., 2.],
[2., 2., 2., 2.]],
[[3., 3., 3., 3.],
[3., 3., 3., 3.]],
[[4., 4., 4., 4.],
[4., 4., 4., 4.]]]])
And I want to rearrange them to look like this
tensor([[[1., 1., 1., 1., 2., 2., 2., 2.],
[1., 1., 1., 1., 2., 2., 2., 2.],
[3., 3., 3., 3., 4., 4., 4., 4.],
[3., 3., 3., 3., 4., 4., 4., 4.]]])
However the solution I was hoping would work obviously doesn't and while I understand why it doesn't work I'll share it.
b, t, x, y = X.shape
num_x_splits = num_y_splits = 2
X = X.reshape(-1,x*num_x_splits,y*num_y_splits)
tensor([[[1., 1., 1., 1., 1., 1., 1., 1.],
[2., 2., 2., 2., 2., 2., 2., 2.],
[3., 3., 3., 3., 3., 3., 3., 3.],
[4., 4., 4., 4., 4., 4., 4., 4.]]])
Is there a computationally efficient way I can accomplish what I want?
I did some more research and looks like the ideal solution might actually be a combinatoin of the accepted answer and to use the einops package which provides a high-level, easy-to-read, efficient solution