Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
12 changes: 12 additions & 0 deletions src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1239,13 +1239,25 @@ function (\)(A::AbstractMatrix, B::AbstractVecOrMat)
if istril(A)
if istriu(A)
return Diagonal(A) \ B
elseif istriu(A, -1)
return Bidiagonal(A, :L) \ B
else
return LowerTriangular(A) \ B
end
end
if istriu(A)
if istril(A, 1)
return Bidiagonal(A, :U) \ B
end
return UpperTriangular(A) \ B
end
if isbanded(A, -1, 1)
T = Tridiagonal(A)
if issymmetric(T)
return SymTridiagonal(T) \ B
end
return lu(T) \ B
end
return lu(A) \ B
end
return qr(A, ColumnNorm()) \ 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