In short I want to index into a matrix and add to each row.
F = zeros(Int64,5)
idx = [2,5,2] # same row repeated several times
fi = [5,2,7]
F[idx] += fi
When there is repetition, I would just write a loop:
for (i, f) in zip(idx, fi)
F[i] += f
(not that sorting by
idx may improve performance)
You could also use
view(F, idx) .+= fi
But the way @Tamas_Papp recommended might be more explicit and legible.
Just for fun, you can also try broadcasting:
((i,f) -> F[i]+=f).(idx,fi)
Performance-wise, a loop will always be faster, though.