Skip to content
Open
7 changes: 4 additions & 3 deletions src/factorization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ patterns with “more structure”.
Base.@kwdef struct UMFPACKFactorization <: AbstractFactorization
reuse_symbolic::Bool = true
check_pattern::Bool = true # Check factorization re-use
control::Vector{Float64}=SparseArrays.UMFPACK.get_umfpack_control(Float64,Int64) # Control Parameters of UMFPACK
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will heap allocate each time in the default algorithm. Instead, make a const of the default, set the default here to nothing, and then if nothing use the const global.

end

const PREALLOCATED_UMFPACK = SparseArrays.UMFPACK.UmfpackLU(SparseMatrixCSC(0, 0, [1],
Expand Down Expand Up @@ -782,15 +783,15 @@ function SciMLBase.solve!(cache::LinearCache, alg::UMFPACKFactorization; kwargs.
fact = lu(
SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A),
nonzeros(A)),
check = false)
check = false, control=alg.control)
else
fact = lu!(cacheval,
SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A),
nonzeros(A)), check = false)
nonzeros(A)), check = false, control=alg.control)
end
else
fact = lu(SparseMatrixCSC(size(A)..., getcolptr(A), rowvals(A), nonzeros(A)),
check = false)
check = false, control=alg.control)
end
cache.cacheval = fact
cache.isfresh = false
Expand Down
12 changes: 12 additions & 0 deletions test/controlvectortest.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using SparseArrays, LinearSolve

A = sparse(rand(3,3));
b=rand(3);
prob = LinearProblem(A, b);

#check without contro Vector
u=solve(prob,UMFPACKFactorization()).u

#check plugging in a control vector
controlv=SparseArrays.UMFPACK.get_umfpack_control(Float64,Int64)
u=solve(prob,UMFPACKFactorization(control=controlv)).u