Provided that A is a SparseMatrixCSC, you will have to write a special routine that updates its nzval in the relevant places, based on colptr and rowval. If the structure of F is unchanged, I don't think you need to change rowval at all. If you really want to optimize this, I am afraid there is no way around doing the messy part.
You can make this a bit more generic this way: write a function sparseupdater(A, I, J, F) that, the sparsity structure is equivalent, returns a vector p of integers, perhaps wrapped in some type, with the property that for (p,v) in zip(p,F.nzval) A.nzval[p] = v end performs A[I,J] = F. Then you just do u = sparseupdater(A, I, J, F) for something in hot_loop A[u] = F end where A[u]=F calls a setindex! method that calls the loop above to update nzval. PS: All code above is a sketch and may contain typos. On Fri, Aug 19 2016, Gabriel Goh wrote: > Hey, > > I have a sparse matrix > > A = [ C D > E F ] > > now if I want to update F with another matrix with the exact same sparsity > structure, what would be the easiest way to do it efficiently? Ideally, I'd > just update the relevant values in rowval directly, but it seems messy to > extract which indicies correspond to what. > > Thanks! > Gabe
