Skip to content

Commit bfa01f9

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

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
@@ -1131,6 +1131,7 @@ function generic_trimatdiv!(C::AbstractVecOrMat, uploc, isunitc, tfun::Function,
11311131
if size(C) != size(B)
11321132
throw(DimensionMismatch("size of output, $(size(C)), does not match size of right hand side, $(size(B))"))
11331133
end
1134+
iszero(mA) && return C
11341135
oA = oneunit(eltype(A))
11351136
@inbounds if uploc == 'U'
11361137
if isunitc == 'N'
@@ -1267,6 +1268,7 @@ function generic_trimatdiv!(C::AbstractVecOrMat, uploc, isunitc, ::Function, xA:
12671268
if size(C) != size(B)
12681269
throw(DimensionMismatch("size of output, $(size(C)), does not match size of right hand side, $(size(B))"))
12691270
end
1271+
iszero(mA) && return C
12701272
oA = oneunit(eltype(A))
12711273
@inbounds if uploc == 'U'
12721274
if isunitc == 'N'

stdlib/LinearAlgebra/test/lu.jl

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

483+
@testset "lu for empty matrices" begin
484+
for T in (Float64, BigFloat)
485+
A = fill(T(0.0), 0, 0)
486+
v = fill(T(1.0), 0, 10)
487+
@test A \ v lu(A) \ v
488+
vt = permutedims(v)
489+
@test vt / A vt / lu(A)
490+
B = UpperTriangular(transpose(fill(complex(T(0.0)), 0, 0)'))
491+
@test B \ v v
492+
@test vt / B vt
493+
end
494+
end
495+
483496
end # module TestLU

0 commit comments

Comments
 (0)