I asked the same question about GitHub, and we came to the following conclusion. The SparseVector type was added with Julia 0.4 and with it the BLAS function LinAlg.axpy !, which updates in place the (possibly dense) vector x sparse vector y times scalar a , i.e. efficiently performs x += a*y . However, in Julia 0.4 it is not executed properly. It only works in Julia 0.5
@time for i=1:100000 LinAlg.axpy!(1,A[:,i],w) end 1.041587 seconds (799.49 k allocations: 1.530 GB, 8.01% gc time)
However, this code is still not optimal, as it creates SparseVector A [:, i]. You can get an even faster version with the following function:
function upd!(w,A,i,c) rowval = A.rowval nzval = A.nzval @inbounds for j = nzrange(A,i) w[rowval[j]] += c* nzval[j] end return w end @time for i=1:100000 upd!(w,A,i,1) end 0.500323 seconds (99.49 k allocations: 1.518 MB)
This is exactly what I needed to achieve, after some research we managed to get there, thanks to everyone!
source share