If the sparsity patterns are guaranteed to always be static and identical, how about reusing the colptr
and rowval
vectors, as in this example:
julia> A = sprandn(10, 10, 0.05)
10×10 SparseMatrixCSC{Float64,Int64} with 5 stored entries:
[3 , 1] = -0.00762068
[4 , 3] = 0.24252
[3 , 5] = -0.357867
[3 , 9] = 0.451247
[7 , 9] = 0.810302
julia> B = SparseMatrixCSC(size(A)..., SparseArrays.getcolptr(A), rowvals(A), rand(nnz(A)))
10×10 SparseMatrixCSC{Float64,Int64} with 5 stored entries:
[3 , 1] = 0.506203
[4 , 3] = 0.719589
[3 , 5] = 0.336872
[3 , 9] = 0.949761
[7 , 9] = 0.59247