11module LinearSolveSparseArraysExt
22
33using LinearSolve: LinearSolve, BLASELTYPES, pattern_changed, ArrayInterface,
4- @get_cacheval , CHOLMODFactorization, GenericFactorization, GenericLUFactorization,
5- KLUFactorization, LUFactorization, NormalCholeskyFactorization, OperatorAssumptions,
6- QRFactorization, RFLUFactorization, UMFPACKFactorization, solve
4+ @get_cacheval , CHOLMODFactorization, GenericFactorization,
5+ GenericLUFactorization,
6+ KLUFactorization, LUFactorization, NormalCholeskyFactorization,
7+ OperatorAssumptions,
8+ QRFactorization, RFLUFactorization, UMFPACKFactorization, solve
79using ArrayInterface: ArrayInterface
810using LinearAlgebra: LinearAlgebra, I, Hermitian, Symmetric, cholesky, ldiv!, lu, lu!, QR
9- using SparseArrays: SparseArrays, AbstractSparseArray, AbstractSparseMatrixCSC, SparseMatrixCSC,
11+ using SparseArrays: SparseArrays, AbstractSparseArray, AbstractSparseMatrixCSC,
12+ SparseMatrixCSC,
1013 nonzeros, rowvals, getcolptr, sparse, sprand
1114using SparseArrays. UMFPACK: UMFPACK_OK
1215using Base: / , \ , convert
@@ -107,23 +110,25 @@ function LinearSolve.init_cacheval(
107110 alg:: LUFactorization , A:: AbstractSparseArray{T, Int64} , b, u,
108111 Pl, Pr,
109112 maxiters:: Int , abstol, reltol,
110- verbose:: Bool , assumptions:: OperatorAssumptions ) where {T<: BLASELTYPES }
113+ verbose:: Bool , assumptions:: OperatorAssumptions ) where {T <: BLASELTYPES }
111114 if LinearSolve. is_cusparse (A)
112115 ArrayInterface. lu_instance (A)
113116 else
114- SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC {T, Int64} (zero (Int64), zero (Int64), [Int64 (1 )], Int64[], T[]))
117+ SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC {T, Int64} (
118+ zero (Int64), zero (Int64), [Int64 (1 )], Int64[], T[]))
115119 end
116120end
117121
118122function LinearSolve. init_cacheval (
119123 alg:: LUFactorization , A:: AbstractSparseArray{T, Int32} , b, u,
120124 Pl, Pr,
121125 maxiters:: Int , abstol, reltol,
122- verbose:: Bool , assumptions:: OperatorAssumptions ) where {T<: BLASELTYPES }
126+ verbose:: Bool , assumptions:: OperatorAssumptions ) where {T <: BLASELTYPES }
123127 if LinearSolve. is_cusparse (A)
124128 ArrayInterface. lu_instance (A)
125129 else
126- SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC {T, Int32} (zero (Int32), zero (Int32), [Int32 (1 )], Int32[], T[]))
130+ SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC {T, Int32} (
131+ zero (Int32), zero (Int32), [Int32 (1 )], Int32[], T[]))
127132 end
128133end
129134
@@ -140,7 +145,6 @@ function LinearSolve.init_cacheval(
140145 maxiters:: Int , abstol,
141146 reltol,
142147 verbose:: Bool , assumptions:: OperatorAssumptions )
143-
144148 PREALLOCATED_UMFPACK
145149end
146150
@@ -156,16 +160,18 @@ function LinearSolve.init_cacheval(
156160 alg:: UMFPACKFactorization , A:: AbstractSparseArray{T, Int64} , b, u,
157161 Pl, Pr,
158162 maxiters:: Int , abstol, reltol,
159- verbose:: Bool , assumptions:: OperatorAssumptions ) where {T<: BLASELTYPES }
160- SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC {T, Int64} (zero (Int64), zero (Int64), [Int64 (1 )], Int64[], T[]))
163+ verbose:: Bool , assumptions:: OperatorAssumptions ) where {T <: BLASELTYPES }
164+ SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC {T, Int64} (
165+ zero (Int64), zero (Int64), [Int64 (1 )], Int64[], T[]))
161166end
162167
163168function LinearSolve. init_cacheval (
164169 alg:: UMFPACKFactorization , A:: AbstractSparseArray{T, Int32} , b, u,
165170 Pl, Pr,
166171 maxiters:: Int , abstol, reltol,
167- verbose:: Bool , assumptions:: OperatorAssumptions ) where {T<: BLASELTYPES }
168- SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC {T, Int32} (zero (Int32), zero (Int32), [Int32 (1 )], Int32[], T[]))
172+ verbose:: Bool , assumptions:: OperatorAssumptions ) where {T <: BLASELTYPES }
173+ SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC {T, Int32} (
174+ zero (Int32), zero (Int32), [Int32 (1 )], Int32[], T[]))
169175end
170176
171177function SciMLBase. solve! (
@@ -197,7 +203,8 @@ function SciMLBase.solve!(
197203 F = LinearSolve. @get_cacheval (cache, :UMFPACKFactorization )
198204 if F. status == UMFPACK_OK
199205 y = ldiv! (cache. u, F, cache. b)
200- SciMLBase. build_linear_solution (alg, y, nothing , cache; retcode = ReturnCode. Success)
206+ SciMLBase. build_linear_solution (
207+ alg, y, nothing , cache; retcode = ReturnCode. Success)
201208 else
202209 SciMLBase. build_linear_solution (
203210 alg, cache. u, nothing , cache; retcode = ReturnCode. Infeasible)
@@ -236,7 +243,8 @@ function LinearSolve.init_cacheval(
236243 maxiters:: Int , abstol,
237244 reltol,
238245 verbose:: Bool , assumptions:: OperatorAssumptions )
239- KLU. KLUFactorization (SparseMatrixCSC {Float64, Int32} (0 , 0 , [Int32 (1 )], Int32[], Float64[]))
246+ KLU. KLUFactorization (SparseMatrixCSC {Float64, Int32} (
247+ 0 , 0 , [Int32 (1 )], Int32[], Float64[]))
240248end
241249
242250# TODO : guard this against errors
@@ -266,14 +274,15 @@ function SciMLBase.solve!(cache::LinearSolve.LinearCache, alg::KLUFactorization;
266274 F = LinearSolve. @get_cacheval (cache, :KLUFactorization )
267275 if F. common. status == KLU. KLU_OK
268276 y = ldiv! (cache. u, F, cache. b)
269- SciMLBase. build_linear_solution (alg, y, nothing , cache; retcode = ReturnCode. Success)
277+ SciMLBase. build_linear_solution (
278+ alg, y, nothing , cache; retcode = ReturnCode. Success)
270279 else
271280 SciMLBase. build_linear_solution (
272281 alg, cache. u, nothing , cache; retcode = ReturnCode. Infeasible)
273282 end
274283end
275284
276- const PREALLOCATED_CHOLMOD = cholesky (sparse (reshape ([1.0 ],1 , 1 )))
285+ const PREALLOCATED_CHOLMOD = cholesky (sparse (reshape ([1.0 ], 1 , 1 )))
277286
278287function LinearSolve. init_cacheval (alg:: CHOLMODFactorization ,
279288 A:: Union{SparseMatrixCSC{T, Int}, Symmetric{T, SparseMatrixCSC{T, Int}}} , b, u,
@@ -290,7 +299,7 @@ function LinearSolve.init_cacheval(alg::CHOLMODFactorization,
290299 maxiters:: Int , abstol, reltol,
291300 verbose:: Bool , assumptions:: OperatorAssumptions ) where {T < :
292301 BLASELTYPES}
293- cholesky (sparse (reshape ([one (T)],1 , 1 )))
302+ cholesky (sparse (reshape ([one (T)], 1 , 1 )))
294303end
295304
296305function LinearSolve. init_cacheval (alg:: CHOLMODFactorization ,
@@ -368,7 +377,8 @@ function LinearSolve.init_cacheval(
368377 nothing
369378end
370379
371- function LinearSolve. init_cacheval (alg:: QRFactorization , A:: SparseMatrixCSC{Float64, <:Integer} , b, u, Pl, Pr,
380+ function LinearSolve. init_cacheval (
381+ alg:: QRFactorization , A:: SparseMatrixCSC{Float64, <:Integer} , b, u, Pl, Pr,
372382 maxiters:: Int , abstol, reltol, verbose:: Bool ,
373383 assumptions:: OperatorAssumptions )
374384 ArrayInterface. qr_instance (convert (AbstractMatrix, A), alg. pivot)
0 commit comments