Skip to content

Default to QR with BandedMatrix{BigFloat} #598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions ext/LinearSolveBandedMatricesExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ function defaultalg(A::BandedMatrix, b, oa::OperatorAssumptions{Bool})
end
end

function defaultalg(
A::BandedMatrix{T}, b, oa::OperatorAssumptions{Bool}) where {T <: BigFloat}
return DefaultLinearSolver(DefaultAlgorithmChoice.QRFactorization)
end

function defaultalg(A::Symmetric{<:Number, <:BandedMatrix}, b, ::OperatorAssumptions{Bool})
return DefaultLinearSolver(DefaultAlgorithmChoice.CholeskyFactorization)
end
Expand All @@ -42,8 +47,9 @@ for alg in (:SVDFactorization, :MKLLUFactorization, :DiagonalFactorization,
end
end

function init_cacheval(::LUFactorization, A::BandedMatrix, b, u, Pl, Pr, maxiters::Int,
abstol, reltol, verbose::Bool, assumptions::OperatorAssumptions)
function init_cacheval(::LUFactorization, A::BandedMatrix{T}, b, u, Pl, Pr, maxiters::Int,
abstol, reltol, verbose::Bool, assumptions::OperatorAssumptions) where {T}
(T <: BigFloat) && return qr(similar(A, 0, 0))
return lu(similar(A, 0, 0))
end

Expand Down
4 changes: 2 additions & 2 deletions test/adjoint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ db12 = ForwardDiff.gradient(x -> f(eltype(x).(A), x), copy(b1))
@test db1 ≈ db12

# Test complex numbers
A = rand(n, n) + 1im*rand(n, n);
b1 = rand(n) + 1im*rand(n);
A = rand(n, n) + 1im * rand(n, n);
b1 = rand(n) + 1im * rand(n);

function f3(A, b1, b2; alg = KrylovJL_GMRES())
prob = LinearProblem(A, b1)
Expand Down
6 changes: 6 additions & 0 deletions test/banded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ A = AlmostBandedMatrix(BandedMatrix(fill(2.0, n + 2, n), (1, 1)), fill(3.0, 2, n
A[band(0)] .+= 1:n

@test_nowarn solve(LinearProblem(A, b))

# Workaround for no lu from BandedMatrices
A = BandedMatrix{BigFloat}(ones(3, 3), (0, 0))
b = BigFloat[1, 2, 3]
prob = LinearProblem(A, b)
@test_nowarn solve(prob)
2 changes: 1 addition & 1 deletion test/defaults_loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ prob = LinearProblem(mat, rhs)

using Sparspak
sol = solve(prob).u
@test sol isa Vector{BigFloat}
@test sol isa Vector{BigFloat}
Loading