Tensor Views
PyTorch allows a tensor to be a "View" of an existing tensor. View
tensor shares the same underlying data with its base tensor.
Supporting "View" avoids explicit data copy, thus allows us to do fast
and memory efficient reshaping, slicing and element-wise operations.
For example, to get a view of an existing tensor "t", you can call
"t.view(...)".



t = torch.rand(4, 4)
b = t.view(2, 8)
t.storage().data_ptr() == b.storage().data_ptr()  # t and b share the same underlying data.
   True
   # Modifying view tensor changes base tensor as well.
b[0][0] = 3.14
t[0][0]
   tensor(3.14)



Since views share underlying data with its base tensor, if you edit
the data in the view, it will be reflected in the base tensor as well.
Typically a PyTorch op returns a new tensor as output, e.g. "add()".
But in case of view ops, outputs are views of input tensors to avoid
unnecessary data copy. No data movement occurs when creating a view,