Good way to copy 2 tensors with different shape but same number of elements

For example I have 2 tensor:
x = torch.randn(4)
y = torch.randn(2, 2)
If I want to copy y to x I have to do this:
x.copy_(y.view(x.shape))
Is there any more efficient ways to do it ? I notice that torch7 is able to do x:copy(y) but pytorch can’t.

The view operation will change some meta data of the tensor and will not copy y, so you shouldn’t see any performance hits.