How Tensor.view works?

I’m looking into a more deep explanations about how Tensor.view works, looking into old forums it doesn’t allow non contiguous tensors, but now acording to documentation and what I’ve been playing it seems it does with some restrictions, however is not very clear to me how.

If I understood right there are two cases, view is a subspan of the original dimensions, that is (source.rank() > view.rank()) or it expands the rank of the source (opossite case) if the view have more dimensions than the source then the following condition should be meet:

stride[i] == stride[i+1] * shape[i+1] for dimension < rank to dimension = source.rank

However is not very clear to me how final strides are calculated for the rest of the view, since docs stops there and it confuzes me a bit.

Hi @EricHermosis, do check out this blog to understand PyTorch’s internals, including the concepts of strides and views