Is there a way to create a rolled (shifted and wrapped) view of a tensor?

I believe the answer to this question is simply no, but I would like to confirm with somebody with more experience.

Given a tensor [0, 1, 2, 3, 4, 5], is there a way to create a view [1, 2, 3, 4, 5, 0] without a memory copy?

As an extension, is this possible in more dimensions? That is, could a 2D image be rolled both horizontally and vertically?

See torch.roll(input, shifts, dims=None)

Not sure how I missed that, thanks. By the looks of the kernel implementation torch.roll does a copy, so it seems safe to presume that it can’t be done with a view. My understanding of the stride/offset system also implies that conclusion, so that makes sense. I’m happy to call that a confirmation and solution.

1 Like