Skip to content

Commit 6fe3b2a

Browse files
committed
Defaults for Banded Matrices
1 parent 0843b53 commit 6fe3b2a

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

Project.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LinearSolve"
22
uuid = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
33
authors = ["SciML"]
4-
version = "2.10.0"
4+
version = "2.11.0"
55

66
[deps]
77
ArrayInterface = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
@@ -31,6 +31,7 @@ SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
3131
UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
3232

3333
[weakdeps]
34+
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
3435
BlockDiagonals = "0a1fb500-61f7-11e9-3c65-f5ef3456f9f0"
3536
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
3637
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
@@ -42,6 +43,7 @@ Metal = "dde4c033-4e86-420c-a63e-0dd931031962"
4243
Pardiso = "46dd5b70-b6fb-5a00-ae2d-e8fea33afaf2"
4344

4445
[extensions]
46+
LinearSolveBandedMatricesExt = "BandedMatrices"
4547
LinearSolveBlockDiagonalsExt = "BlockDiagonals"
4648
LinearSolveCUDAExt = "CUDA"
4749
LinearSolveEnzymeExt = "Enzyme"
@@ -54,6 +56,7 @@ LinearSolvePardisoExt = "Pardiso"
5456

5557
[compat]
5658
ArrayInterface = "7.4.11"
59+
BandedMatrices = "1"
5760
BlockDiagonals = "0.1"
5861
ConcreteStructs = "0.2"
5962
DocStringExtensions = "0.8, 0.9"
@@ -80,6 +83,7 @@ UnPack = "1"
8083
julia = "1.6"
8184

8285
[extras]
86+
BandedMatrices = "aae01518-5342-5314-be14-df237901396f"
8387
BlockDiagonals = "0a1fb500-61f7-11e9-3c65-f5ef3456f9f0"
8488
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
8589
FiniteDiff = "6a86dc24-6348-571c-b903-95158fe2bd41"

ext/LinearSolveBandedMatricesExt.jl

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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

src/common.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ However, in practice this computation is very expensive and thus not possible fo
1414
Therefore, OperatorCondition lets one share to LinearSolve the expected conditioning. The higher the
1515
expected condition number, the safer the algorithm needs to be and thus there is a trade-off between
1616
numerical performance and stability. By default the method assumes the operator may be ill-conditioned
17-
for the standard linear solvers to converge (such as LU-factorization), though more extreme
17+
for the standard linear solvers to converge (such as LU-factorization), though more extreme
1818
ill-conditioning or well-conditioning could be the case and specified through this assumption.
1919
"""
2020
EnumX.@enumx OperatorCondition begin

src/default.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function defaultalg(A, b, assump::OperatorAssumptions)
163163
DefaultAlgorithmChoice.GenericLUFactorization
164164
elseif VERSION >= v"1.8" && appleaccelerate_isavailable()
165165
DefaultAlgorithmChoice.AppleAccelerateLUFactorization
166-
elseif (length(b) <= 100 || (isopenblas() && length(b) <= 500) ||
166+
elseif (length(b) <= 100 || (isopenblas() && length(b) <= 500) ||
167167
(usemkl && length(b) <= 200)) &&
168168
(A === nothing ? eltype(b) <: Union{Float32, Float64} :
169169
eltype(A) <: Union{Float32, Float64})

0 commit comments

Comments
 (0)