267
267
268
268
Base. @kwdef struct UMFPACKFactorization <: AbstractFactorization
269
269
reuse_symbolic:: Bool = true
270
+ check:: Bool = true # Check factorization re-use
270
271
end
271
272
272
273
function init_cacheval (alg:: UMFPACKFactorization , A, b, u, Pl, Pr, maxiters:: Int , abstol,
@@ -290,7 +291,13 @@ function SciMLBase.solve(cache::LinearCache, alg::UMFPACKFactorization; kwargs..
290
291
if cache. isfresh
291
292
if cache. cacheval != = nothing && alg. reuse_symbolic
292
293
# Caches the symbolic factorization: https://github.com/JuliaLang/julia/pull/33738
293
- fact = lu! (cache. cacheval, A)
294
+ if alg. check && ! (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
294
301
else
295
302
fact = lu (A)
296
303
end
303
310
304
311
Base. @kwdef struct KLUFactorization <: AbstractFactorization
305
312
reuse_symbolic:: Bool = true
313
+ check:: Bool = true
306
314
end
307
315
308
316
function init_cacheval (alg:: KLUFactorization , A, b, u, Pl, Pr, maxiters:: Int , abstol,
@@ -316,14 +324,20 @@ function SciMLBase.solve(cache::LinearCache, alg::KLUFactorization; kwargs...)
316
324
A = convert (AbstractMatrix, A)
317
325
if cache. isfresh
318
326
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 && ! (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)
325
340
end
326
- fact = KLU. klu! (cache. cacheval, A)
327
341
else
328
342
# New fact each time since the sparsity pattern can change
329
343
# and thus it needs to reallocate
0 commit comments