From 48169a81011fbfef2a97c3df90a9b7b446d264db Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Mon, 14 Apr 2025 22:42:26 +0530 Subject: [PATCH 1/2] Fix `lmul!`/`rmul!` for 0-sized matrices --- src/bidiag.jl | 2 ++ test/bidiag.jl | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/src/bidiag.jl b/src/bidiag.jl index d2f9e624..60fbc7e5 100644 --- a/src/bidiag.jl +++ b/src/bidiag.jl @@ -538,6 +538,7 @@ function lmul!(D::Diagonal, B::Bidiagonal) matmul_size_check(size(D), size(B)) (; dv, ev) = B isL = B.uplo == 'L' + iszero(size(D,1)) && return B dv[1] = D.diag[1] * dv[1] for i in axes(ev,1) ev[i] = D.diag[i + isL] * ev[i] @@ -575,6 +576,7 @@ function rmul!(B::Bidiagonal, D::Diagonal) matmul_size_check(size(B), size(D)) (; dv, ev) = B isU = B.uplo == 'U' + iszero(size(D,1)) && return B dv[1] *= D.diag[1] for i in axes(ev,1) ev[i] *= D.diag[i + isU] diff --git a/test/bidiag.jl b/test/bidiag.jl index 6fa851dd..e111433d 100644 --- a/test/bidiag.jl +++ b/test/bidiag.jl @@ -1192,4 +1192,13 @@ end @test_throws msg ldiv!(C, B, zeros(2,1)) end +@testset "l/rmul with 0-sized matrices" begin + n = 0 + B = Bidiagonal(ones(n), ones(max(n-1,0)), :U) + B2 = copy(B) + D = Diagonal(ones(n)) + @test lmul!(D, B) == B2 + @test rmul!(B, D) == B2 +end + end # module TestBidiagonal From 4aca27487e9ece7afe11a1922d7f086fe55f8f4f Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Mon, 14 Apr 2025 23:05:25 +0530 Subject: [PATCH 2/2] Add `@inbounds` annotation --- src/bidiag.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bidiag.jl b/src/bidiag.jl index 60fbc7e5..05c1371c 100644 --- a/src/bidiag.jl +++ b/src/bidiag.jl @@ -539,8 +539,8 @@ function lmul!(D::Diagonal, B::Bidiagonal) (; dv, ev) = B isL = B.uplo == 'L' iszero(size(D,1)) && return B - dv[1] = D.diag[1] * dv[1] - for i in axes(ev,1) + @inbounds dv[1] = D.diag[1] * dv[1] + @inbounds for i in axes(ev,1) ev[i] = D.diag[i + isL] * ev[i] dv[i+1] = D.diag[i+1] * dv[i+1] end @@ -577,8 +577,8 @@ function rmul!(B::Bidiagonal, D::Diagonal) (; dv, ev) = B isU = B.uplo == 'U' iszero(size(D,1)) && return B - dv[1] *= D.diag[1] - for i in axes(ev,1) + @inbounds dv[1] *= D.diag[1] + @inbounds for i in axes(ev,1) ev[i] *= D.diag[i + isU] dv[i+1] *= D.diag[i+1] end