In place lufact for sparse matrices and prellocation for lufact output

Currently there is a lufact! for dense matrices. Is there an equivalent of lufact! for sparse matrices?

Also, related to that, how do I preallocate for the output of lufact(A), assuming that A is a sparse matrix? This is what I have tried:

S = lufact(speye(5))
S .= lufact(sparse(rand(5,5)))

MethodError: no method matching broadcast!(::Base.#identity, 
::Base.SparseArrays.UMFPACK.UmfpackLU{Float64,Int64}, ::Base.SparseArrays.UMFPACK.UmfpackLU{Float64,Int64})

My code has a loop that solves Ax=b where A stays constant but b changes every time during the loop. I think it’d help if I store the output of lufact(A) in terms of memory allocations (be it through preallocation or in-place operation).

1 Like

Sparse factorizations are quite different so it is not possible to preallocate the memory. In short, the reason is that for sparse factorizations you don’t know how much memory you’ll need before you compute the factorization. Factorizing the matrix before the loop is still a good idea, though, so just compute F = lufact(Asparse) outside the loop.

2 Likes