Is permute() lazy?

I believe that by permute is lazy in that sense as it returns a view rather than a copied tensor. However, this also means that the result isn’t guaranteed to be contiguous:

>>> import torch
>>> a = torch.randn(2, 3, 224, 224)
>>> a.data_ptr()
140712810848320
>>> a.is_contiguous()
True
>>> a = a.permute(0, 2, 3, 1)
>>> a.data_ptr()
140712810848320
>>> a.is_contiguous()
False
>>> 

1 Like