@@ -52,15 +52,15 @@ function LinearSolve.handle_sparsematrixcsc_lu(A::AbstractSparseMatrixCSC)
5252end
5353
5454@static if Base. USE_GPL_LIBS
55- function LinearSolve. defaultalg (
56- A:: Symmetric{<:BLASELTYPES, <:SparseMatrixCSC} , b, :: OperatorAssumptions{Bool} )
57- LinearSolve. DefaultLinearSolver (LinearSolve. DefaultAlgorithmChoice. CHOLMODFactorization)
58- end
55+ function LinearSolve. defaultalg (
56+ A:: Symmetric{<:BLASELTYPES, <:SparseMatrixCSC} , b, :: OperatorAssumptions{Bool} )
57+ LinearSolve. DefaultLinearSolver (LinearSolve. DefaultAlgorithmChoice. CHOLMODFactorization)
58+ end
5959else
60- function LinearSolve. defaultalg (
61- A:: Symmetric{<:BLASELTYPES, <:SparseMatrixCSC} , b, :: OperatorAssumptions{Bool} )
62- LinearSolve. DefaultLinearSolver (LinearSolve. DefaultAlgorithmChoice. CholeskyFactorization)
63- end
60+ function LinearSolve. defaultalg (
61+ A:: Symmetric{<:BLASELTYPES, <:SparseMatrixCSC} , b, :: OperatorAssumptions{Bool} )
62+ LinearSolve. DefaultLinearSolver (LinearSolve. DefaultAlgorithmChoice. CholeskyFactorization)
63+ end
6464end # @static if Base.USE_GPL_LIBS
6565
6666function LinearSolve. defaultalg (A:: AbstractSparseMatrixCSC{Tv, Ti} , b,
@@ -87,8 +87,8 @@ function LinearSolve.init_cacheval(alg::GenericFactorization,
8787end
8888
8989@static if Base. USE_GPL_LIBS
90- const PREALLOCATED_UMFPACK = SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC (0 , 0 , [1 ],
91- Int[], Float64[]))
90+ const PREALLOCATED_UMFPACK = SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC (0 , 0 , [1 ],
91+ Int[], Float64[]))
9292end # @static if Base.USE_GPL_LIBS
9393
9494function LinearSolve. init_cacheval (
@@ -116,39 +116,37 @@ function LinearSolve.init_cacheval(
116116end
117117
118118@static if Base. USE_GPL_LIBS
119- function LinearSolve. init_cacheval (
120- alg:: LUFactorization , A:: AbstractSparseArray{Float64, Int64} , b, u,
121- Pl, Pr,
122- maxiters:: Int , abstol, reltol,
123- verbose:: LinearVerbosity , assumptions:: OperatorAssumptions )
124- PREALLOCATED_UMFPACK
125- end
126-
127- function LinearSolve. init_cacheval (
128- alg:: LUFactorization , A:: AbstractSparseArray{T, Int64} , b, u,
129- Pl, Pr,
130- maxiters:: Int , abstol, reltol,
131- verbose:: LinearVerbosity , assumptions:: OperatorAssumptions ) where {T <: BLASELTYPES }
132- if LinearSolve. is_cusparse (A)
133- ArrayInterface. lu_instance (A)
134- else
135- SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC {T, Int64} (
136- zero (Int64), zero (Int64), [Int64 (1 )], Int64[], T[]))
137- end
119+ function LinearSolve. init_cacheval (
120+ alg:: LUFactorization , A:: AbstractSparseArray{Float64, Int64} , b, u,
121+ Pl, Pr,
122+ maxiters:: Int , abstol, reltol,
123+ verbose:: LinearVerbosity , assumptions:: OperatorAssumptions )
124+ PREALLOCATED_UMFPACK
125+ end
126+ function LinearSolve. init_cacheval (
127+ alg:: LUFactorization , A:: AbstractSparseArray{T, Int64} , b, u,
128+ Pl, Pr,
129+ maxiters:: Int , abstol, reltol,
130+ verbose:: LinearVerbosity , assumptions:: OperatorAssumptions ) where {T <: BLASELTYPES }
131+ if LinearSolve. is_cusparse (A)
132+ ArrayInterface. lu_instance (A)
133+ else
134+ SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC {T, Int64} (
135+ zero (Int64), zero (Int64), [Int64 (1 )], Int64[], T[]))
138136 end
139-
140- function LinearSolve. init_cacheval (
141- alg:: LUFactorization , A:: AbstractSparseArray{T, Int32} , b, u,
142- Pl, Pr,
143- maxiters:: Int , abstol, reltol,
144- verbose:: LinearVerbosity , assumptions:: OperatorAssumptions ) where {T <: BLASELTYPES }
145- if LinearSolve. is_cusparse (A)
146- ArrayInterface. lu_instance (A)
147- else
148- SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC {T, Int32} (
149- zero (Int32), zero (Int32), [Int32 (1 )], Int32[], T[]))
150- end
137+ end
138+ function LinearSolve. init_cacheval (
139+ alg:: LUFactorization , A:: AbstractSparseArray{T, Int32} , b, u,
140+ Pl, Pr,
141+ maxiters:: Int , abstol, reltol,
142+ verbose:: LinearVerbosity , assumptions:: OperatorAssumptions ) where {T <: BLASELTYPES }
143+ if LinearSolve. is_cusparse (A)
144+ ArrayInterface. lu_instance (A)
145+ else
146+ SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC {T, Int32} (
147+ zero (Int32), zero (Int32), [Int32 (1 )], Int32[], T[]))
151148 end
149+ end
152150end # @static if Base.USE_GPL_LIBS
153151
154152function LinearSolve. init_cacheval (
@@ -168,76 +166,76 @@ function LinearSolve.init_cacheval(
168166end
169167
170168@static if Base. USE_GPL_LIBS
171- function LinearSolve. init_cacheval (
172- alg:: UMFPACKFactorization , A:: AbstractSparseArray{Float64, Int} , b, u, Pl, Pr,
173- maxiters:: Int , abstol,
174- reltol,
175- verbose:: LinearVerbosity , assumptions:: OperatorAssumptions )
169+ function LinearSolve. init_cacheval (
170+ alg:: UMFPACKFactorization , A:: AbstractSparseArray{Float64, Int} , b, u, Pl, Pr,
171+ maxiters:: Int , abstol,
172+ reltol,
173+ verbose:: LinearVerbosity , assumptions:: OperatorAssumptions )
176174 PREALLOCATED_UMFPACK
177- end
175+ end
178176
179- function LinearSolve. init_cacheval (
180- alg:: UMFPACKFactorization , A:: AbstractSparseArray{T, Int64} , b, u,
181- Pl, Pr,
182- maxiters:: Int , abstol, reltol,
183- verbose:: LinearVerbosity , assumptions:: OperatorAssumptions ) where {T <: BLASELTYPES }
184- SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC {T, Int64} (
185- zero (Int64), zero (Int64), [Int64 (1 )], Int64[], T[]))
186- end
177+ function LinearSolve. init_cacheval (
178+ alg:: UMFPACKFactorization , A:: AbstractSparseArray{T, Int64} , b, u,
179+ Pl, Pr,
180+ maxiters:: Int , abstol, reltol,
181+ verbose:: LinearVerbosity , assumptions:: OperatorAssumptions ) where {T <: BLASELTYPES }
182+ SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC {T, Int64} (
183+ zero (Int64), zero (Int64), [Int64 (1 )], Int64[], T[]))
184+ end
187185
188- function LinearSolve. init_cacheval (
189- alg:: UMFPACKFactorization , A:: AbstractSparseArray{T, Int32} , b, u,
190- Pl, Pr,
191- maxiters:: Int , abstol, reltol,
192- verbose:: LinearVerbosity , assumptions:: OperatorAssumptions ) where {T <: BLASELTYPES }
193- SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC {T, Int32} (
194- zero (Int32), zero (Int32), [Int32 (1 )], Int32[], T[]))
195- end
186+ function LinearSolve. init_cacheval (
187+ alg:: UMFPACKFactorization , A:: AbstractSparseArray{T, Int32} , b, u,
188+ Pl, Pr,
189+ maxiters:: Int , abstol, reltol,
190+ verbose:: LinearVerbosity , assumptions:: OperatorAssumptions ) where {T <: BLASELTYPES }
191+ SparseArrays. UMFPACK. UmfpackLU (SparseMatrixCSC {T, Int32} (
192+ zero (Int32), zero (Int32), [Int32 (1 )], Int32[], T[]))
193+ end
196194
197- function SciMLBase. solve! (
198- cache:: LinearSolve.LinearCache , alg:: UMFPACKFactorization ; kwargs... )
199- A = cache. A
200- A = convert (AbstractMatrix, A)
201- if cache. isfresh
202- cacheval = LinearSolve. @get_cacheval (cache, :UMFPACKFactorization )
203- if alg. reuse_symbolic
204- # Caches the symbolic factorization: https://github.com/JuliaLang/julia/pull/33738
205- if alg. check_pattern && pattern_changed (cacheval, A)
206- fact = lu (
207- SparseMatrixCSC (size (A)... , getcolptr (A), rowvals (A),
208- nonzeros (A)),
209- check = false )
210- else
211- fact = lu! (cacheval,
212- SparseMatrixCSC (size (A)... , getcolptr (A), rowvals (A),
213- nonzeros (A)), check = false )
214- end
215- else
195+ function SciMLBase. solve! (
196+ cache:: LinearSolve.LinearCache , alg:: UMFPACKFactorization ; kwargs... )
197+ A = cache. A
198+ A = convert (AbstractMatrix, A)
199+ if cache. isfresh
200+ cacheval = LinearSolve. @get_cacheval (cache, :UMFPACKFactorization )
201+ if alg. reuse_symbolic
202+ # Caches the symbolic factorization: https://github.com/JuliaLang/julia/pull/33738
203+ if alg. check_pattern && pattern_changed (cacheval, A)
216204 fact = lu (
217- SparseMatrixCSC (size (A)... , getcolptr (A), rowvals (A), nonzeros (A)),
205+ SparseMatrixCSC (size (A)... , getcolptr (A), rowvals (A),
206+ nonzeros (A)),
218207 check = false )
208+ else
209+ fact = lu! (cacheval,
210+ SparseMatrixCSC (size (A)... , getcolptr (A), rowvals (A),
211+ nonzeros (A)), check = false )
219212 end
220- cache. cacheval = fact
221- cache. isfresh = false
222- end
223-
224- F = LinearSolve. @get_cacheval (cache, :UMFPACKFactorization )
225- if F. status == UMFPACK_OK
226- y = ldiv! (cache. u, F, cache. b)
227- SciMLBase. build_linear_solution (
228- alg, y, nothing , cache; retcode = ReturnCode. Success)
229213 else
230- @SciMLMessage ( " Solver failed " , cache . verbose, :solver_failure )
231- SciMLBase . build_linear_solution (
232- alg, cache . u, nothing , cache; retcode = ReturnCode . Infeasible )
214+ fact = lu (
215+ SparseMatrixCSC ( size (A) ... , getcolptr (A), rowvals (A), nonzeros (A)),
216+ check = false )
233217 end
218+ cache. cacheval = fact
219+ cache. isfresh = false
234220 end
235221
236- else
237- function SciMLBase. solve! (
238- cache:: LinearSolve.LinearCache , alg:: UMFPACKFactorization ; kwargs... )
239- error (" UMFPACKFactorization requires GPL libraries (UMFPACK). Rebuild Julia with USE_GPL_LIBS=1 or use an alternative algorithm like SparspakFactorization" )
222+ F = LinearSolve. @get_cacheval (cache, :UMFPACKFactorization )
223+ if F. status == UMFPACK_OK
224+ y = ldiv! (cache. u, F, cache. b)
225+ SciMLBase. build_linear_solution (
226+ alg, y, nothing , cache; retcode = ReturnCode. Success)
227+ else
228+ @SciMLMessage (" Solver failed" , cache. verbose, :solver_failure )
229+ SciMLBase. build_linear_solution (
230+ alg, cache. u, nothing , cache; retcode = ReturnCode. Infeasible)
240231 end
232+ end
233+
234+ else
235+ function SciMLBase. solve! (
236+ cache:: LinearSolve.LinearCache , alg:: UMFPACKFactorization ; kwargs... )
237+ error (" UMFPACKFactorization requires GPL libraries (UMFPACK). Rebuild Julia with USE_GPL_LIBS=1 or use an alternative algorithm like SparspakFactorization" )
238+ end
241239end # @static if Base.USE_GPL_LIBS
242240
243241function LinearSolve. init_cacheval (
@@ -320,25 +318,25 @@ function LinearSolve.init_cacheval(alg::CHOLMODFactorization,
320318end
321319
322320@static if Base. USE_GPL_LIBS
323- const PREALLOCATED_CHOLMOD = cholesky (sparse (reshape ([1.0 ], 1 , 1 )))
321+ const PREALLOCATED_CHOLMOD = cholesky (sparse (reshape ([1.0 ], 1 , 1 )))
324322
325- function LinearSolve. init_cacheval (alg:: CHOLMODFactorization ,
326- A:: Union{SparseMatrixCSC{T, Int}, Symmetric{T, SparseMatrixCSC{T, Int}}} , b, u,
327- Pl, Pr,
328- maxiters:: Int , abstol, reltol,
329- verbose:: LinearVerbosity , assumptions:: OperatorAssumptions ) where {T < :
323+ function LinearSolve. init_cacheval (alg:: CHOLMODFactorization ,
324+ A:: Union{SparseMatrixCSC{T, Int}, Symmetric{T, SparseMatrixCSC{T, Int}}} , b, u,
325+ Pl, Pr,
326+ maxiters:: Int , abstol, reltol,
327+ verbose:: LinearVerbosity , assumptions:: OperatorAssumptions ) where {T < :
330328 Float64}
331- PREALLOCATED_CHOLMOD
332- end
329+ PREALLOCATED_CHOLMOD
330+ end
333331
334- function LinearSolve. init_cacheval (alg:: CHOLMODFactorization ,
335- A:: Union{SparseMatrixCSC{T, Int}, Symmetric{T, SparseMatrixCSC{T, Int}}} , b, u,
336- Pl, Pr,
337- maxiters:: Int , abstol, reltol,
338- verbose:: LinearVerbosity , assumptions:: OperatorAssumptions ) where {T < :
332+ function LinearSolve. init_cacheval (alg:: CHOLMODFactorization ,
333+ A:: Union{SparseMatrixCSC{T, Int}, Symmetric{T, SparseMatrixCSC{T, Int}}} , b, u,
334+ Pl, Pr,
335+ maxiters:: Int , abstol, reltol,
336+ verbose:: LinearVerbosity , assumptions:: OperatorAssumptions ) where {T < :
339337 BLASELTYPES}
340- cholesky (sparse (reshape ([one (T)], 1 , 1 )))
341- end
338+ cholesky (sparse (reshape ([one (T)], 1 , 1 )))
339+ end
342340end # @static if Base.USE_GPL_LIBS
343341
344342function LinearSolve. init_cacheval (alg:: NormalCholeskyFactorization ,
@@ -375,26 +373,24 @@ end
375373
376374@static if Base. USE_GPL_LIBS
377375 # SPQR and CHOLMOD Factor support
378- function LinearSolve. _ldiv! (x:: Vector ,
379- A:: Union{SparseArrays.SPQR.QRSparse, SparseArrays.CHOLMOD.Factor} , b:: Vector )
380- x .= A \ b
381- end
382-
383- function LinearSolve. _ldiv! (x:: AbstractVector ,
384- A:: Union{SparseArrays.SPQR.QRSparse, SparseArrays.CHOLMOD.Factor} , b:: AbstractVector )
385- x .= A \ b
386- end
387-
388- function LinearSolve. _ldiv! (:: SVector ,
389- A:: Union{SparseArrays.CHOLMOD.Factor, SparseArrays.SPQR.QRSparse} ,
390- b:: AbstractVector )
391- (A \ b)
392- end
393- function LinearSolve. _ldiv! (:: SVector ,
394- A:: Union{SparseArrays.CHOLMOD.Factor, SparseArrays.SPQR.QRSparse} ,
395- b:: SVector )
396- (A \ b)
397- end
376+ function LinearSolve. _ldiv! (x:: Vector ,
377+ A:: Union{SparseArrays.SPQR.QRSparse, SparseArrays.CHOLMOD.Factor} , b:: Vector )
378+ x .= A \ b
379+ end
380+ function LinearSolve. _ldiv! (x:: AbstractVector ,
381+ A:: Union{SparseArrays.SPQR.QRSparse, SparseArrays.CHOLMOD.Factor} , b:: AbstractVector )
382+ x .= A \ b
383+ end
384+ function LinearSolve. _ldiv! (:: SVector ,
385+ A:: Union{SparseArrays.CHOLMOD.Factor, SparseArrays.SPQR.QRSparse} ,
386+ b:: AbstractVector )
387+ (A \ b)
388+ end
389+ function LinearSolve. _ldiv! (:: SVector ,
390+ A:: Union{SparseArrays.CHOLMOD.Factor, SparseArrays.SPQR.QRSparse} ,
391+ b:: SVector )
392+ (A \ b)
393+ end
398394end # @static if Base.USE_GPL_LIBS
399395
400396function LinearSolve. pattern_changed (fact, A:: SparseArrays.SparseMatrixCSC )
@@ -404,29 +400,29 @@ function LinearSolve.pattern_changed(fact, A::SparseArrays.SparseMatrixCSC)
404400end
405401
406402@static if Base. USE_GPL_LIBS
407- function LinearSolve. defaultalg (
408- A:: AbstractSparseMatrixCSC{<:Union{Float64, ComplexF64}, Ti} , b,
409- assump:: OperatorAssumptions{Bool} ) where {Ti}
410- if assump. issq
411- if length (b) <= 10_000 && length (nonzeros (A)) / length (A) < 2e-4
412- LinearSolve. DefaultLinearSolver (LinearSolve. DefaultAlgorithmChoice. KLUFactorization)
413- else
414- LinearSolve. DefaultLinearSolver (LinearSolve. DefaultAlgorithmChoice. UMFPACKFactorization)
415- end
403+ function LinearSolve. defaultalg (
404+ A:: AbstractSparseMatrixCSC{<:Union{Float64, ComplexF64}, Ti} , b,
405+ assump:: OperatorAssumptions{Bool} ) where {Ti}
406+ if assump. issq
407+ if length (b) <= 10_000 && length (nonzeros (A)) / length (A) < 2e-4
408+ LinearSolve. DefaultLinearSolver (LinearSolve. DefaultAlgorithmChoice. KLUFactorization)
416409 else
417- LinearSolve. DefaultLinearSolver (LinearSolve. DefaultAlgorithmChoice. QRFactorization )
410+ LinearSolve. DefaultLinearSolver (LinearSolve. DefaultAlgorithmChoice. UMFPACKFactorization )
418411 end
412+ else
413+ LinearSolve. DefaultLinearSolver (LinearSolve. DefaultAlgorithmChoice. QRFactorization)
419414 end
415+ end
420416else
421- function LinearSolve. defaultalg (
422- A:: AbstractSparseMatrixCSC{<:Union{Float64, ComplexF64}, Ti} , b,
423- assump:: OperatorAssumptions{Bool} ) where {Ti}
424- if assump. issq
425- LinearSolve. DefaultLinearSolver (LinearSolve. DefaultAlgorithmChoice. KLUFactorization)
426- elseif ! assump. issq
427- LinearSolve. DefaultLinearSolver (LinearSolve. DefaultAlgorithmChoice. QRFactorization)
428- end
417+ function LinearSolve. defaultalg (
418+ A:: AbstractSparseMatrixCSC{<:Union{Float64, ComplexF64}, Ti} , b,
419+ assump:: OperatorAssumptions{Bool} ) where {Ti}
420+ if assump. issq
421+ LinearSolve. DefaultLinearSolver (LinearSolve. DefaultAlgorithmChoice. KLUFactorization)
422+ elseif ! assump. issq
423+ LinearSolve. DefaultLinearSolver (LinearSolve. DefaultAlgorithmChoice. QRFactorization)
429424 end
425+ end
430426end # @static if Base.USE_GPL_LIBS
431427
432428# SPQR Handling
0 commit comments