Skip to content

Commit

Permalink
Fix generic triangular solves with empty matrices (#54201)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8945914)
  • Loading branch information
dkarrasch authored and KristofferC committed Jul 24, 2024
1 parent 6c58b41 commit bfa01f9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions stdlib/LinearAlgebra/src/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@ function generic_trimatdiv!(C::AbstractVecOrMat, uploc, isunitc, tfun::Function,
if size(C) != size(B)
throw(DimensionMismatch("size of output, $(size(C)), does not match size of right hand side, $(size(B))"))
end
iszero(mA) && return C
oA = oneunit(eltype(A))
@inbounds if uploc == 'U'
if isunitc == 'N'
Expand Down Expand Up @@ -1267,6 +1268,7 @@ function generic_trimatdiv!(C::AbstractVecOrMat, uploc, isunitc, ::Function, xA:
if size(C) != size(B)
throw(DimensionMismatch("size of output, $(size(C)), does not match size of right hand side, $(size(B))"))
end
iszero(mA) && return C
oA = oneunit(eltype(A))
@inbounds if uploc == 'U'
if isunitc == 'N'
Expand Down
13 changes: 13 additions & 0 deletions stdlib/LinearAlgebra/test/lu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,17 @@ end
LinearAlgebra.generic_lufact!(fill(Inf, 2, 2), check=false)
end

@testset "lu for empty matrices" begin
for T in (Float64, BigFloat)
A = fill(T(0.0), 0, 0)
v = fill(T(1.0), 0, 10)
@test A \ v lu(A) \ v
vt = permutedims(v)
@test vt / A vt / lu(A)
B = UpperTriangular(transpose(fill(complex(T(0.0)), 0, 0)'))
@test B \ v v
@test vt / B vt
end
end

end # module TestLU

0 comments on commit bfa01f9

Please sign in to comment.