Skip to content

Commit

Permalink
Ensure bidiagonal setindex! does not read indices in error message (#…
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
jishnub authored and KristofferC committed Oct 9, 2024
1 parent a620a4e commit 4b55053
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/src/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ end
@inbounds A.ev[j] = x
elseif !iszero(x)
throw(ArgumentError(LazyString(lazy"cannot set entry ($i, $j) off the ",
istriu(A) ? "upper" : "lower", " bidiagonal band to a nonzero value ", x)))
A.uplo == 'U' ? "upper" : "lower", " bidiagonal band to a nonzero value ", x)))
end
return x
end
Expand Down
5 changes: 5 additions & 0 deletions stdlib/LinearAlgebra/test/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -822,4 +822,9 @@ end
@test all(iszero, diag(B, 1))
end

@testset "off-band indexing error" begin
B = Bidiagonal(Vector{BigInt}(undef, 4), Vector{BigInt}(undef,3), :L)
@test_throws "cannot set entry" B[1,2] = 4
end

end # module TestBidiagonal

0 comments on commit 4b55053

Please sign in to comment.