OpenNMT issue with PyTorch: .copy_ function not clear behavior
I'm working with the PyTorch version OpenNMT and I'm trying to modify the Beam Search algorithm. I'm currently stuck in the  beam_update function (in OpenNMT-py/onmt/decoders/decoder.py file). When it is called:

sent_states.data.copy_(
                sent_states.data.index_select(1, positions))


according to the pythorch documentation of the .copy_ function it will 


  Copies the elements from src into self tensor and returns self.


But, what is "self tensor" referring to? Can someone explain to me what this function do or point me to the source code, since I cannot find it...

The self tensor is the tensor you call copy_ on.
In your example it is sent_states.data.



To answer the question raised in the comments: Why does copy not behave like assigning with = 

.copy() creates a real copy to a new memory location, while assigning with = only stores a reference to the memory location.

The code below shows the difference in execution:

import torch

torch.manual_seed(3515)
tensor1 = torch.rand(2, 3)
tensor2 = torch.rand(2, 2)
tensor3 = torch.rand(2, 3)
positions = torch.tensor([2, 0])

tensor2.data.copy_(tensor1.data.index_select(1, positions))
tensor3.data = tensor1.data.index_select(1, positions)
print(tensor2)
print(tensor3)
print(id(tensor1.data[0]))
print(id(tensor2.data[0]))
print(id(tensor3.data[0]))


Output:

tensor([[ 0.5939,  0.8861],
        [ 0.7525,  0.1537]])
tensor([[ 0.5939,  0.8861],
        [ 0.7525,  0.1537]])
4583187080
4583187008
4583187080


The location of tensor1 and tensor3 are the same, while tensor2 has been copied to a new location
