Skip to content

Commit 77475c1

Browse files
authored
Fix lmul!/rmul! for 0-sized matrices (#1290)
Fixes scaling `Bidiaognal` matrices by `Diagonal` ones when they're both empty.
1 parent c3d35c0 commit 77475c1

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/bidiag.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,9 @@ function lmul!(D::Diagonal, B::Bidiagonal)
538538
matmul_size_check(size(D), size(B))
539539
(; dv, ev) = B
540540
isL = B.uplo == 'L'
541-
dv[1] = D.diag[1] * dv[1]
542-
for i in axes(ev,1)
541+
iszero(size(D,1)) && return B
542+
@inbounds dv[1] = D.diag[1] * dv[1]
543+
@inbounds for i in axes(ev,1)
543544
ev[i] = D.diag[i + isL] * ev[i]
544545
dv[i+1] = D.diag[i+1] * dv[i+1]
545546
end
@@ -575,8 +576,9 @@ function rmul!(B::Bidiagonal, D::Diagonal)
575576
matmul_size_check(size(B), size(D))
576577
(; dv, ev) = B
577578
isU = B.uplo == 'U'
578-
dv[1] *= D.diag[1]
579-
for i in axes(ev,1)
579+
iszero(size(D,1)) && return B
580+
@inbounds dv[1] *= D.diag[1]
581+
@inbounds for i in axes(ev,1)
580582
ev[i] *= D.diag[i + isU]
581583
dv[i+1] *= D.diag[i+1]
582584
end

test/bidiag.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,4 +1192,13 @@ end
11921192
@test_throws msg ldiv!(C, B, zeros(2,1))
11931193
end
11941194

1195+
@testset "l/rmul with 0-sized matrices" begin
1196+
n = 0
1197+
B = Bidiagonal(ones(n), ones(max(n-1,0)), :U)
1198+
B2 = copy(B)
1199+
D = Diagonal(ones(n))
1200+
@test lmul!(D, B) == B2
1201+
@test rmul!(B, D) == B2
1202+
end
1203+
11951204
end # module TestBidiagonal

0 commit comments

Comments
 (0)