no… index_add_ is exactly what you need. why do you do ones_like(values)? can you look at the docs before complaining?
>>> x = torch.zeros(5)
>>> x.index_add_(0, torch.tensor([0, 0, 4, 1]), torch.ones(4))
tensor([2., 1., 0., 0., 1.])