267267
268268Base. @kwdef struct UMFPACKFactorization <: AbstractFactorization
269269 reuse_symbolic:: Bool = true
270+ check_pattern:: Bool = true # Check factorization re-use
270271end
271272
272273function init_cacheval (alg:: UMFPACKFactorization , A, b, u, Pl, Pr, maxiters:: Int , abstol,
@@ -290,7 +291,13 @@ function SciMLBase.solve(cache::LinearCache, alg::UMFPACKFactorization; kwargs..
290291 if cache. isfresh
291292 if cache. cacheval != = nothing && alg. reuse_symbolic
292293 # Caches the symbolic factorization: https://github.com/JuliaLang/julia/pull/33738
293- fact = lu! (cache. cacheval, A)
294+ if alg. check_pattern && ! (SuiteSparse. decrement (SparseArrays. getcolptr (A)) ==
295+ cache. cacheval. colptr &&
296+ SuiteSparse. decrement (SparseArrays. getrowval (A)) == cache. cacheval. rowval)
297+ fact = lu (A)
298+ else
299+ fact = lu! (cache. cacheval, A)
300+ end
294301 else
295302 fact = lu (A)
296303 end
303310
304311Base. @kwdef struct KLUFactorization <: AbstractFactorization
305312 reuse_symbolic:: Bool = true
313+ check_pattern:: Bool = true
306314end
307315
308316function init_cacheval (alg:: KLUFactorization , A, b, u, Pl, Pr, maxiters:: Int , abstol,
@@ -316,14 +324,20 @@ function SciMLBase.solve(cache::LinearCache, alg::KLUFactorization; kwargs...)
316324 A = convert (AbstractMatrix, A)
317325 if cache. isfresh
318326 if cache. cacheval != = nothing && alg. reuse_symbolic
319- # If we have a cacheval already, run umfpack_symbolic to ensure the symbolic factorization exists
320- # This won't recompute if it does.
321- KLU. klu_analyze! (cache. cacheval)
322- copyto! (cache. cacheval. nzval, A. nzval)
323- if cache. cacheval. _numeric === C_NULL # We MUST have a numeric factorization for reuse, unlike UMFPACK.
324- KLU. klu_factor! (cache. cacheval)
327+ if alg. check_pattern && ! (SuiteSparse. decrement (SparseArrays. getcolptr (A)) ==
328+ cache. cacheval. colptr &&
329+ SuiteSparse. decrement (SparseArrays. getrowval (A)) == cache. cacheval. rowval)
330+ fact = KLU. klu (A)
331+ else
332+ # If we have a cacheval already, run umfpack_symbolic to ensure the symbolic factorization exists
333+ # This won't recompute if it does.
334+ KLU. klu_analyze! (cache. cacheval)
335+ copyto! (cache. cacheval. nzval, A. nzval)
336+ if cache. cacheval. _numeric === C_NULL # We MUST have a numeric factorization for reuse, unlike UMFPACK.
337+ KLU. klu_factor! (cache. cacheval)
338+ end
339+ fact = KLU. klu! (cache. cacheval, A)
325340 end
326- fact = KLU. klu! (cache. cacheval, A)
327341 else
328342 # New fact each time since the sparsity pattern can change
329343 # and thus it needs to reallocate
0 commit comments