Skip to content

Commit b5c04a4

Browse files
dkarraschKristofferC
authored andcommitted
Fix generic triangular solves with empty matrices (#54201)
(cherry picked from commit 8945914)
1 parent c84b516 commit b5c04a4

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

stdlib/LinearAlgebra/src/triangular.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,7 @@ function generic_trimatdiv!(C::AbstractVecOrMat, uploc, isunitc, tfun::Function,
12311231
if size(C) != size(B)
12321232
throw(DimensionMismatch(lazy"size of output, $(size(C)), does not match size of right hand side, $(size(B))"))
12331233
end
1234+
iszero(mA) && return C
12341235
oA = oneunit(eltype(A))
12351236
@inbounds if uploc == 'U'
12361237
if isunitc == 'N'
@@ -1367,6 +1368,7 @@ function generic_trimatdiv!(C::AbstractVecOrMat, uploc, isunitc, ::Function, xA:
13671368
if size(C) != size(B)
13681369
throw(DimensionMismatch(lazy"size of output, $(size(C)), does not match size of right hand side, $(size(B))"))
13691370
end
1371+
iszero(mA) && return C
13701372
oA = oneunit(eltype(A))
13711373
@inbounds if uploc == 'U'
13721374
if isunitc == 'N'

stdlib/LinearAlgebra/test/lu.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,17 @@ end
486486
LinearAlgebra.generic_lufact!(fill(Inf, 2, 2), check=false)
487487
end
488488

489+
@testset "lu for empty matrices" begin
490+
for T in (Float64, BigFloat)
491+
A = fill(T(0.0), 0, 0)
492+
v = fill(T(1.0), 0, 10)
493+
@test A \ v lu(A) \ v
494+
vt = permutedims(v)
495+
@test vt / A vt / lu(A)
496+
B = UpperTriangular(transpose(fill(complex(T(0.0)), 0, 0)'))
497+
@test B \ v v
498+
@test vt / B vt
499+
end
500+
end
501+
489502
end # module TestLU

0 commit comments

Comments
 (0)