In-place add to an array using duplicate indices

numpy functions are just loop in C.

well just make your own function that runs faster than numpy (maybe, untested):

julia> function add_at(out, addrs, v) # this is for scalar v
           for i in addrs
               out[i] += v
           end
           return out
       end
add_at (generic function with 2 methods)

julia> function add_at(out, addrs, vals::AbstractArray)
           length(addrs) == length(vals) || error("unmatching length")
           for (i,v) in zip(addrs, vals)
               out[i] += v
           end
           return out
       end
2 Likes