|
| 1 | +module LinearSolveBandedMatricesExt |
| 2 | + |
| 3 | +using BandedMatrices, LinearAlgebra, LinearSolve |
| 4 | +import LinearSolve: defaultalg, |
| 5 | + do_factorization, init_cacheval, DefaultLinearSolver, DefaultAlgorithmChoice |
| 6 | + |
| 7 | +# Defaults for BandedMatrices |
| 8 | +function defaultalg(A::BandedMatrix, b, ::OperatorAssumptions) |
| 9 | + return DefaultLinearSolver(DefaultAlgorithmChoice.QRFactorization) |
| 10 | +end |
| 11 | + |
| 12 | +function defaultalg(A::Symmetric{<:Number, <:BandedMatrix}, b, ::OperatorAssumptions) |
| 13 | + return DefaultLinearSolver(DefaultAlgorithmChoice.CholeskyFactorization) |
| 14 | +end |
| 15 | + |
| 16 | +# BandedMatrices `qr` doesn't allow other args without causing an ambiguity |
| 17 | +do_factorization(alg::QRFactorization, A::BandedMatrix, b, u) = alg.inplace ? qr!(A) : qr(A) |
| 18 | + |
| 19 | +function do_factorization(alg::LUFactorization, A::BandedMatrix, b, u) |
| 20 | + _pivot = alg.pivot isa NoPivot ? Val(false) : Val(true) |
| 21 | + return lu!(A, _pivot; check = false) |
| 22 | +end |
| 23 | + |
| 24 | +# For BandedMatrix |
| 25 | +for alg in (:SVDFactorization, :MKLLUFactorization, :DiagonalFactorization, |
| 26 | + :SparspakFactorization, :KLUFactorization, :UMFPACKFactorization, |
| 27 | + :GenericLUFactorization, :RFLUFactorization, :BunchKaufmanFactorization, |
| 28 | + :CHOLMODFactorization, :NormalCholeskyFactorization, :LDLtFactorization, |
| 29 | + :AppleAccelerateLUFactorization, :CholeskyFactorization) |
| 30 | + @eval begin |
| 31 | + function init_cacheval(::$(alg), ::BandedMatrix, b, u, Pl, Pr, maxiters::Int, |
| 32 | + abstol, reltol, verbose::Bool, assumptions::OperatorAssumptions) |
| 33 | + return nothing |
| 34 | + end |
| 35 | + end |
| 36 | +end |
| 37 | + |
| 38 | +function init_cacheval(::LUFactorization, A::BandedMatrix, b, u, Pl, Pr, maxiters::Int, |
| 39 | + abstol, reltol, verbose::Bool, assumptions::OperatorAssumptions) |
| 40 | + return lu(similar(A, 0, 0)) |
| 41 | +end |
| 42 | + |
| 43 | +# For Symmetric BandedMatrix |
| 44 | +for alg in (:SVDFactorization, :MKLLUFactorization, :DiagonalFactorization, |
| 45 | + :SparspakFactorization, :KLUFactorization, :UMFPACKFactorization, |
| 46 | + :GenericLUFactorization, :RFLUFactorization, :BunchKaufmanFactorization, |
| 47 | + :CHOLMODFactorization, :NormalCholeskyFactorization, |
| 48 | + :AppleAccelerateLUFactorization, :QRFactorization, :LUFactorization) |
| 49 | + @eval begin |
| 50 | + function init_cacheval(::$(alg), ::Symmetric{<:Number, <:BandedMatrix}, b, u, Pl, |
| 51 | + Pr, maxiters::Int, abstol, reltol, verbose::Bool, |
| 52 | + assumptions::OperatorAssumptions) |
| 53 | + return nothing |
| 54 | + end |
| 55 | + end |
| 56 | +end |
| 57 | + |
| 58 | +end |
0 commit comments