Skip to content

Commit

Permalink
Add destructive version of sparse lufact
Browse files Browse the repository at this point in the history
As discussed on irc with Viral, lufact! should avoid making a copy of the
original matrix. It assumes ownership and clears the user's matrix to
indicate such. This isn't entirely foolproof; the user could break
things by keeping a reference to the original arrays and modifying them
after calling lufact!.
  • Loading branch information
mlubin committed May 22, 2012
1 parent 3313365 commit b4554bd
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions extras/linalg_suitesparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,31 @@ function lufact{Tv<:Union(Float64,Complex128),Ti<:Union(Int64,Int32)}(S::SparseM

end

function lufact!{Tv<:Union(Float64,Complex128),Ti<:Union(Int64,Int32)}(S::SparseMatrixCSC{Tv,Ti})
Scopy = SparseMatrixCSC(S.m,S.n,S.colptr,S.rowval,S.nzval)
Scopy = _jl_convert_to_0_based_indexing!(Scopy)
numeric = []

try
symbolic = _jl_umfpack_symbolic(Scopy)
numeric = _jl_umfpack_numeric(Scopy, symbolic)
catch e
Scopy = _jl_convert_to_1_based_indexing!(Scopy)
if is(e,MatrixIllConditionedException)
error("Input matrix is ill conditioned or singular");
else
error("Error calling UMFPACK")
end
end

S.rowval = []
S.nzval = []
S.colptr = zeros(S.n+1)

return UmfpackLUFactorization(numeric,Scopy)

end

function (\){Tv<:Union(Float64,Complex128),
Ti<:Union(Int64,Int32)}(S::SparseMatrixCSC{Tv,Ti}, b::Vector{Tv})
return _jl_sparse_lusolve(S,b)
Expand Down

0 comments on commit b4554bd

Please sign in to comment.