Is .contiguous().flatten() the same as .view(-1) in PyTorch?
Are these exactly the same?
myTensor.contiguous().flatten()
myTensor.view(-1)

Will they return the same auto grad function etc?

No, they are not exactly the same.

myTensor.contiguous().flatten():

Here, contiguous() either returns a copy of myTensor stored in contiguous memory, or returns myTensor itself if it is already contiguous. Then, flatten() reshapes the tensor to a single dimension. However, the returned tensor could be the same object as myTensor, a view, or a copy, so the contiguity of the output is not guaranteed.
Relevant documentation:

It’s also worth mentioning a few ops with special behaviors:

reshape(), reshape_as() and flatten() can return either a view or new tensor, user code shouldn’t rely on whether it’s view or not.

contiguous() returns itself if input tensor is already contiguous, otherwise it returns a new contiguous tensor by copying data.




myTensor.view(-1):

Here, view() returns a tensor with the same data as myTensor, and will only work if myTensor is already contiguous. The result may not be contiguous depending on the shape of myTensor.
