Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #38346: Eigen decomposition of Symmetric Matrix containing NaNs now throws exception #38408

Merged
merged 7 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions stdlib/LinearAlgebra/src/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,24 @@ function chkfinite(A::AbstractMatrix)
return true
end

function chkuplofinite(A::AbstractMatrix, uplo::AbstractChar)
kc611 marked this conversation as resolved.
Show resolved Hide resolved
require_one_based_indexing(A)
m, n = size(A)
if uplo == 'U'
@inbounds for j in 1:n, i in 1:j
if !isfinite(A[i,j])
throw(ArgumentError("matrix contains Infs or NaNs"))
end
end
else
@inbounds for j in 1:n, i in j:m
if !isfinite(A[i,j])
throw(ArgumentError("matrix contains Infs or NaNs"))
end
end
end
end

# LAPACK version number
function version()
major = Ref{BlasInt}(0)
Expand Down Expand Up @@ -5030,6 +5048,7 @@ for (syev, syevr, sygvd, elty) in
vl::AbstractFloat, vu::AbstractFloat, il::Integer, iu::Integer, abstol::AbstractFloat)
chkstride1(A)
n = checksquare(A)
chkuplofinite(A, uplo)
if range == 'I' && !(1 <= il <= iu <= n)
throw(ArgumentError("illegal choice of eigenvalue indices (il = $il, iu = $iu), which must be between 1 and n = $n"))
end
Expand Down
6 changes: 5 additions & 1 deletion stdlib/LinearAlgebra/test/eigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ end
@test_throws(ArgumentError, eigen(fill(eltya, 1, 1)))
@test_throws(ArgumentError, eigen(fill(eltya, 2, 2)))
test_matrix = rand(typeof(eltya),3,3)
test_matrix[2,2] = eltya
test_matrix[1,3] = eltya
@test_throws(ArgumentError, eigen(test_matrix))
@test_throws(ArgumentError, eigen(Symmetric(test_matrix)))
@test_throws(ArgumentError, eigen(Hermitian(test_matrix)))
@test eigen(Symmetric(test_matrix, :L)) isa Eigen
@test eigen(Hermitian(test_matrix, :L)) isa Eigen
end
end

Expand Down