Skip to content

Add banded paths to generic solve #1372

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 12 additions & 4 deletions src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1236,14 +1236,22 @@ function (\)(A::AbstractMatrix, B::AbstractVecOrMat)
require_one_based_indexing(A, B)
m, n = size(A)
if m == n
if istril(A)
if istriu(A)
return Diagonal(A) \ B
istrium1 = istriu(A, -1)
istril1 = istril(A, 1)
if istril1 && iszero(diagview(A,1)) # istril(A)
if istrium1
if iszero(diagview(A, -1))
return Diagonal(A) \ B
end
return Bidiagonal(A, :L) \ B
else
return LowerTriangular(A) \ B
end
end
if istriu(A)
if istrium1 && iszero(diagview(A, -1)) # istriu(A)
if istril1
return Bidiagonal(A, :U) \ B
end
return UpperTriangular(A) \ B
end
return lu(A) \ B
Expand Down
12 changes: 12 additions & 0 deletions test/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -937,4 +937,16 @@ end
@test B == A2
end

@testset "linear solve for dense banded matrices" begin
b = randn(5)
for A in (diagm(0=>1:5, -1=>1:4, 1=>1:4), # SymTridiagonal
diagm(0=>1:5, -1=>1:4, 1=>5:8), # Tridiagonal
diagm(0=>1:5, 1=>1:4), # Upper Bidiagonal
diagm(0=>1:5, -1=>1:4), # Lower Bidiagonal
)
x = A \ b
@test A * x ≈ b
end
end

end # module TestGeneric