Skip to content

Commit f355c06

Browse files
remove comment out
1 parent 2d8678d commit f355c06

File tree

2 files changed

+72
-92
lines changed

2 files changed

+72
-92
lines changed

.github/workflows/Downstream.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
os: [ubuntu-latest]
1818
package:
1919
- {user: SciML, repo: OrdinaryDiffEq.jl, group: InterfaceII}
20+
- {user: SciML, repo: ModelingToolkit.jl, group: All}
21+
- {user: SciML, repo: SciMLSensitivity.jl, group: Core1}
2022

2123
steps:
2224
- uses: actions/checkout@v2

src/factorization.jl

Lines changed: 70 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -70,98 +70,6 @@ function init_cacheval(alg::Union{LUFactorization, GenericLUFactorization}, A, b
7070
ArrayInterfaceCore.lu_instance(convert(AbstractMatrix, A))
7171
end
7272

73-
# This could be a GenericFactorization perhaps?
74-
Base.@kwdef struct UMFPACKFactorization <: AbstractFactorization
75-
reuse_symbolic::Bool = true
76-
end
77-
78-
function init_cacheval(alg::UMFPACKFactorization, A, b, u, Pl, Pr, maxiters, abstol, reltol,
79-
verbose)
80-
A = convert(AbstractMatrix, A)
81-
#=
82-
zerobased = SparseArrays.getcolptr(A)[1] == 0
83-
res = SuiteSparse.UMFPACK.UmfpackLU(C_NULL, C_NULL, size(A, 1), size(A, 2),
84-
zerobased ? copy(SparseArrays.getcolptr(A)) :
85-
SuiteSparse.decrement(SparseArrays.getcolptr(A)),
86-
zerobased ? copy(rowvals(A)) :
87-
SuiteSparse.decrement(rowvals(A)),
88-
copy(nonzeros(A)), 0)
89-
finalizer(SuiteSparse.UMFPACK.umfpack_free_symbolic, res)
90-
=#
91-
res = lu(A; check = false)
92-
@assert res isa SuiteSparse.UMFPACK.UmfpackLU
93-
res
94-
end
95-
96-
function do_factorization(::UMFPACKFactorization, A, b, u)
97-
A = convert(AbstractMatrix, A)
98-
if A isa SparseMatrixCSC
99-
return lu(A)
100-
else
101-
error("Sparse LU is not defined for $(typeof(A))")
102-
end
103-
end
104-
105-
function SciMLBase.solve(cache::LinearCache, alg::UMFPACKFactorization; kwargs...)
106-
A = cache.A
107-
A = convert(AbstractMatrix, A)
108-
if cache.isfresh
109-
if cache.cacheval !== nothing && alg.reuse_symbolic
110-
# If we have a cacheval already, run umfpack_symbolic to ensure the symbolic factorization exists
111-
# This won't recompute if it does.
112-
SuiteSparse.UMFPACK.umfpack_symbolic!(cache.cacheval)
113-
fact = lu!(cache.cacheval, A)
114-
else
115-
fact = do_factorization(alg, A, cache.b, cache.u)
116-
end
117-
cache = set_cacheval(cache, fact)
118-
end
119-
120-
y = ldiv!(cache.u, cache.cacheval, cache.b)
121-
SciMLBase.build_linear_solution(alg, y, nothing, cache)
122-
end
123-
124-
Base.@kwdef struct KLUFactorization <: AbstractFactorization
125-
reuse_symbolic::Bool = true
126-
end
127-
128-
function init_cacheval(alg::KLUFactorization, A, b, u, Pl, Pr, maxiters, abstol, reltol,
129-
verbose)
130-
return KLU.KLUFactorization(convert(AbstractMatrix, A)) # this takes care of the copy internally.
131-
end
132-
133-
function do_factorization(::KLUFactorization, A, b, u)
134-
A = convert(AbstractMatrix, A)
135-
if A isa SparseMatrixCSC
136-
return klu(A)
137-
else
138-
error("KLU is not defined for $(typeof(A))")
139-
end
140-
end
141-
142-
function SciMLBase.solve(cache::LinearCache, alg::KLUFactorization; kwargs...)
143-
A = cache.A
144-
A = convert(AbstractMatrix, A)
145-
if cache.isfresh
146-
if cache.cacheval !== nothing && alg.reuse_symbolic
147-
# If we have a cacheval already, run umfpack_symbolic to ensure the symbolic factorization exists
148-
# This won't recompute if it does.
149-
KLU.klu_analyze!(cache.cacheval)
150-
copyto!(cache.cacheval.nzval, A.nzval)
151-
if cache.cacheval._numeric === C_NULL # We MUST have a numeric factorization for reuse, unlike UMFPACK.
152-
KLU.klu_factor!(cache.cacheval)
153-
end
154-
fact = KLU.klu!(cache.cacheval, A)
155-
else
156-
fact = do_factorization(alg, A, cache.b, cache.u)
157-
end
158-
cache = set_cacheval(cache, fact)
159-
end
160-
161-
y = ldiv!(cache.u, cache.cacheval, cache.b)
162-
SciMLBase.build_linear_solution(alg, y, nothing, cache)
163-
end
164-
16573
## QRFactorization
16674

16775
struct QRFactorization{P} <: AbstractFactorization
@@ -331,6 +239,76 @@ function init_cacheval(alg::Union{GenericFactorization,
331239
do_factorization(alg, newA, b, u)
332240
end
333241

242+
################################## Factorizations which require solve overloads
243+
244+
Base.@kwdef struct UMFPACKFactorization <: AbstractFactorization
245+
reuse_symbolic::Bool = true
246+
end
247+
248+
function init_cacheval(alg::UMFPACKFactorization, A, b, u, Pl, Pr, maxiters, abstol, reltol,
249+
verbose)
250+
A = convert(AbstractMatrix, A)
251+
zerobased = SparseArrays.getcolptr(A)[1] == 0
252+
res = SuiteSparse.UMFPACK.UmfpackLU(C_NULL, C_NULL, size(A, 1), size(A, 2),
253+
zerobased ? copy(SparseArrays.getcolptr(A)) :
254+
SuiteSparse.decrement(SparseArrays.getcolptr(A)),
255+
zerobased ? copy(rowvals(A)) :
256+
SuiteSparse.decrement(rowvals(A)),
257+
copy(nonzeros(A)), 0)
258+
finalizer(SuiteSparse.UMFPACK.umfpack_free_symbolic, res)
259+
res
260+
end
261+
262+
function SciMLBase.solve(cache::LinearCache, alg::UMFPACKFactorization; kwargs...)
263+
A = cache.A
264+
A = convert(AbstractMatrix, A)
265+
if cache.isfresh
266+
if cache.cacheval !== nothing && alg.reuse_symbolic
267+
# Caches the symbolic factorization: https://github.com/JuliaLang/julia/pull/33738
268+
println("factorize"); display(A)
269+
fact = lu!(cache.cacheval, A)
270+
else
271+
fact = do_factorization(alg, A, cache.b, cache.u)
272+
end
273+
cache = set_cacheval(cache, fact)
274+
end
275+
276+
y = ldiv!(cache.u, cache.cacheval, cache.b)
277+
SciMLBase.build_linear_solution(alg, y, nothing, cache)
278+
end
279+
280+
Base.@kwdef struct KLUFactorization <: AbstractFactorization
281+
reuse_symbolic::Bool = true
282+
end
283+
284+
function init_cacheval(alg::KLUFactorization, A, b, u, Pl, Pr, maxiters, abstol, reltol,
285+
verbose)
286+
return KLU.KLUFactorization(convert(AbstractMatrix, A)) # this takes care of the copy internally.
287+
end
288+
289+
function SciMLBase.solve(cache::LinearCache, alg::KLUFactorization; kwargs...)
290+
A = cache.A
291+
A = convert(AbstractMatrix, A)
292+
if cache.isfresh
293+
if cache.cacheval !== nothing && alg.reuse_symbolic
294+
# If we have a cacheval already, run umfpack_symbolic to ensure the symbolic factorization exists
295+
# This won't recompute if it does.
296+
KLU.klu_analyze!(cache.cacheval)
297+
copyto!(cache.cacheval.nzval, A.nzval)
298+
if cache.cacheval._numeric === C_NULL # We MUST have a numeric factorization for reuse, unlike UMFPACK.
299+
KLU.klu_factor!(cache.cacheval)
300+
end
301+
fact = KLU.klu!(cache.cacheval, A)
302+
else
303+
fact = do_factorization(alg, A, cache.b, cache.u)
304+
end
305+
cache = set_cacheval(cache, fact)
306+
end
307+
308+
y = ldiv!(cache.u, cache.cacheval, cache.b)
309+
SciMLBase.build_linear_solution(alg, y, nothing, cache)
310+
end
311+
334312
## RFLUFactorization
335313

336314
struct RFLUFactorization{P, T} <: AbstractFactorization

0 commit comments

Comments
 (0)