Skip to content

Commit c9d09d6

Browse files
jishnubKristofferC
authored andcommitted
Ensure bidiagonal setindex! does not read indices in error message (#55342)
This fixes the error message if the matrix is uninitialized. This is because a `Bidiagonal` with `uplo == 'L'` may still be `istriu` if the subdiaognal is zero. We only care about the band index in the error message, and not the values. (cherry picked from commit f2f188d)
1 parent 7a3e21f commit c9d09d6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

stdlib/LinearAlgebra/src/bidiag.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ end
179179
@inbounds A.ev[j] = x
180180
elseif !iszero(x)
181181
throw(ArgumentError(LazyString(lazy"cannot set entry ($i, $j) off the ",
182-
istriu(A) ? "upper" : "lower", " bidiagonal band to a nonzero value ", x)))
182+
A.uplo == 'U' ? "upper" : "lower", " bidiagonal band to a nonzero value ", x)))
183183
end
184184
return x
185185
end

stdlib/LinearAlgebra/test/bidiag.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,4 +884,9 @@ end
884884
@test mul!(C1, B, sv, 1, 2) == mul!(C2, B, v, 1 ,2)
885885
end
886886

887+
@testset "off-band indexing error" begin
888+
B = Bidiagonal(Vector{BigInt}(undef, 4), Vector{BigInt}(undef,3), :L)
889+
@test_throws "cannot set entry" B[1,2] = 4
890+
end
891+
887892
end # module TestBidiagonal

0 commit comments

Comments
 (0)