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 Aug 19, 2024
1 parent 7a3e21f commit c9d09d6
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 @@ -179,7 +179,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 @@ -884,4 +884,9 @@ end
@test mul!(C1, B, sv, 1, 2) == mul!(C2, B, v, 1 ,2)
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 c9d09d6

Please sign in to comment.