[julia-users] Sparse matrix memory preallocation?
Create the vectors I J V which holds the nonzero rows, columns and values respectively and then call sparse(I, J, V).
[julia-users] Sparse matrix memory preallocation?
Generating a sparse matrix from scratch seems to be quite memory intensive. and slow. Say I wish to create a large block diagonal matrix with 2x2 block entries. Doing it naively is quite slow function f(k) M = spzeros(2*k,2*k) for i = 1:k D = (i-1)*2 + 1:i*2 M[D,D] = randn(2,2)