Suppose I have a memory which I want to update in the following manner:
memory = torch.zeros(4)
indices = torch.LongTensor([1, 2, 3, 1])
values = torch.FloatTensor([1, 10, 100, 1000])
memory[indices] += values
print (memory)
> tensor([   0., 1000.,   10.,  100.])

Here, since there is a repetition in the indices the corresponding values do not get added and only the last one gets added. I can see why that can happen due to simultaneous updates. Is there an easy way to add all the values corresponding to repeated indices
Basically, I want the answer to be
tensor([ 0., 1001., 10., 100.])