diff --git a/stdlib/LinearAlgebra/src/lapack.jl b/stdlib/LinearAlgebra/src/lapack.jl index ef1c8e42c21e4f..5fcf863bf3173f 100644 --- a/stdlib/LinearAlgebra/src/lapack.jl +++ b/stdlib/LinearAlgebra/src/lapack.jl @@ -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) @@ -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 diff --git a/stdlib/LinearAlgebra/test/eigen.jl b/stdlib/LinearAlgebra/test/eigen.jl index 2095a9304690db..48cf70ea06a0c7 100644 --- a/stdlib/LinearAlgebra/test/eigen.jl +++ b/stdlib/LinearAlgebra/test/eigen.jl @@ -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