Hi, I would like to implement the following in PyTorch:
for i in range(indices.shape[0]):
    values[indices[i]] += 1

Both indices and values are 1-D tensors. I found scatter_add which perfectly meets the need:
values.scatter_add_(0, indices, torch.ones_like(values))

However, I found this requires that indices must be shorter than values, otherwise, it will throw an error complaining that indices length too long.
To reproduce, run the following code:
import torch
values = torch.zeros(5)
indices = torch.LongTensor([0, 3, 3])
print(values.scatter_add(0, indices, torch.ones_like(values))) # return tensor([1, 0, 0, 2, 0])

indices = torch.LongTensor([0, 3, 3, 0, 0, 0])
print(values.scatter_add(0, indices, torch.ones_like(values)) # throws error "Expected index [6] to be smaller size than src [5] and to be smaller than tensor [5] apart from dimension 0"

Is it designed in this way, or could there something wrong in the dimension check for this function? Also, is there any way around it?
Thanks.