@@ -49,10 +49,15 @@ Julia's built in `lu`. Equivalent to calling `lu!(A)`
49
49
- pivot: The choice of pivoting. Defaults to `LinearAlgebra.RowMaximum()`. The other choice is
50
50
`LinearAlgebra.NoPivot()`.
51
51
"""
52
- struct LUFactorization{P} <: AbstractFactorization
53
- pivot:: P
52
+ Base. @kwdef struct LUFactorization{P} <: AbstractFactorization
53
+ pivot:: P = LinearAlgebra. RowMaximum ()
54
+ reuse_symbolic:: Bool = true
55
+ check_pattern:: Bool = true # Check factorization re-use
54
56
end
55
57
58
+ # Legacy dispatch
59
+ LUFactorization (pivot) = LUFactorization (;pivot= RowMaximum ())
60
+
56
61
"""
57
62
`GenericLUFactorization(pivot=LinearAlgebra.RowMaximum())`
58
63
@@ -69,10 +74,33 @@ struct GenericLUFactorization{P} <: AbstractFactorization
69
74
pivot:: P
70
75
end
71
76
72
- LUFactorization () = LUFactorization (RowMaximum ())
73
-
74
77
GenericLUFactorization () = GenericLUFactorization (RowMaximum ())
75
78
79
+ function SciMLBase. solve! (cache:: LinearCache , alg:: LUFactorization ; kwargs... )
80
+ A = cache. A
81
+ A = convert (AbstractMatrix, A)
82
+ if cache. isfresh
83
+ cacheval = @get_cacheval (cache, :LUFactorization )
84
+ if A isa AbstractSparseMatrix && alg. reuse_symbolic
85
+ # Caches the symbolic factorization: https://github.com/JuliaLang/julia/pull/33738
86
+ # If SparseMatrixCSC, check if the pattern has changed
87
+ if alg. check_pattern && pattern_changed (cacheval, A)
88
+ fact = lu (A, check = false )
89
+ else
90
+ fact = lu! (cacheval, A, check = false )
91
+ end
92
+ else
93
+ fact = lu (A, check = false )
94
+ end
95
+ cache. cacheval = fact
96
+ cache. isfresh = false
97
+ end
98
+
99
+ F = @get_cacheval (cache, :LUFactorization )
100
+ y = ldiv! (cache. u, F, cache. b)
101
+ SciMLBase. build_linear_solution (alg, y, nothing , cache)
102
+ end
103
+
76
104
function do_factorization (alg:: LUFactorization , A, b, u)
77
105
A = convert (AbstractMatrix, A)
78
106
if A isa AbstractSparseMatrixCSC
@@ -775,10 +803,7 @@ function SciMLBase.solve!(cache::LinearCache, alg::UMFPACKFactorization; kwargs.
775
803
cacheval = @get_cacheval (cache, :UMFPACKFactorization )
776
804
if alg. reuse_symbolic
777
805
# Caches the symbolic factorization: https://github.com/JuliaLang/julia/pull/33738
778
- if alg. check_pattern && ! (SparseArrays. decrement (SparseArrays. getcolptr (A)) ==
779
- cacheval. colptr &&
780
- SparseArrays. decrement (SparseArrays. getrowval (A)) ==
781
- cacheval. rowval)
806
+ if alg. check_pattern && pattern_changed (cacheval, A)
782
807
fact = lu (
783
808
SparseMatrixCSC (size (A)... , getcolptr (A), rowvals (A),
784
809
nonzeros (A)),
@@ -856,10 +881,7 @@ function SciMLBase.solve!(cache::LinearCache, alg::KLUFactorization; kwargs...)
856
881
if cache. isfresh
857
882
cacheval = @get_cacheval (cache, :KLUFactorization )
858
883
if alg. reuse_symbolic
859
- if alg. check_pattern && ! (SparseArrays. decrement (SparseArrays. getcolptr (A)) ==
860
- cacheval. colptr &&
861
- SparseArrays. decrement (SparseArrays. getrowval (A)) ==
862
- cacheval. rowval)
884
+ if alg. check_pattern && pattern_changed (cacheval, A)
863
885
fact = KLU. klu (
864
886
SparseMatrixCSC (size (A)... , getcolptr (A), rowvals (A),
865
887
nonzeros (A)),
0 commit comments