Circular repeat of one dimension

Hi guys,

I have a tensor A = (10,1,4), I need to convert it to B = (10, 5, 4) provided that the second dimension is filled out from the first one in a circular way. That is, B[:,0,:] has values of A[1:5,:] and B[:,1,:] has values of A[2:6,:].

I tried repeat but all the items of B will be exactly as same as A

I’m unsure how this assignment would be possible, as the desired shapes would be different:

Example:

A = torch.randn(10, 1, 4)
print(A[1:5].shape)
> torch.Size([4, 1, 4])

B = torch.randn(10, 5, 4)
B[:, 1:5, :].shape
> torch.Size([10, 4, 4])

As you can see, the slice in A contains 16 elements while the slice in B contains 160 elements.
Could you post an example how B should be filled?
I think you might be able to use A.unfold, but of course the shape mismatch should be solved first.