Skip to content

Commit

Permalink
Fixed #38346: Eigen decomposition of Symmetric Matrix containing NaNs…
Browse files Browse the repository at this point in the history
… now throws exception (#38408)
  • Loading branch information
kc611 authored Dec 9, 2020
1 parent 293e60c commit a813a6e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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)
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

0 comments on commit a813a6e

Please sign in to comment.