Skip to content

Commit 4b55053

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 a620a4e commit 4b55053

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
@@ -166,7 +166,7 @@ end
166166
@inbounds A.ev[j] = x
167167
elseif !iszero(x)
168168
throw(ArgumentError(LazyString(lazy"cannot set entry ($i, $j) off the ",
169-
istriu(A) ? "upper" : "lower", " bidiagonal band to a nonzero value ", x)))
169+
A.uplo == 'U' ? "upper" : "lower", " bidiagonal band to a nonzero value ", x)))
170170
end
171171
return x
172172
end

stdlib/LinearAlgebra/test/bidiag.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,4 +822,9 @@ end
822822
@test all(iszero, diag(B, 1))
823823
end
824824

825+
@testset "off-band indexing error" begin
826+
B = Bidiagonal(Vector{BigInt}(undef, 4), Vector{BigInt}(undef,3), :L)
827+
@test_throws "cannot set entry" B[1,2] = 4
828+
end
829+
825830
end # module TestBidiagonal

0 commit comments

Comments
 (0)