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

18267 1x1 NaN matrix eigenvalue #18526

Merged
merged 8 commits into from
Sep 27, 2016
2 changes: 1 addition & 1 deletion base/linalg/eigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ isposdef(A::Union{Eigen,GeneralizedEigen}) = isreal(A.values) && all(A.values .>

function eigfact!{T<:BlasReal}(A::StridedMatrix{T}; permute::Bool=true, scale::Bool=true)
n = size(A, 2)
n==0 && return Eigen(zeros(T, 0), zeros(T, 0, 0))
n == 0 && return Eigen(zeros(T, 0), zeros(T, 0, 0))
issymmetric(A) && return eigfact!(Symmetric(A))
A, WR, WI, VL, VR, _ = LAPACK.geevx!(permute ? (scale ? 'B' : 'P') : (scale ? 'S' : 'N'), 'N', 'V', 'N', A)
all(WI .== 0.) && return Eigen(WR, VR)
Expand Down
6 changes: 6 additions & 0 deletions base/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,12 @@ function issymmetric(A::AbstractMatrix)
if indsm != indsn
return false
end
if indsm == Base.OneTo(1)
if isnan(A[1,1])
return false
end
return true
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this is sufficient although it will fix the eig issue. For larger matrices, we'd have to check that whole diagonal so instead the loop ranges below should be made one larger to include the diagonal.

for i = first(indsn):last(indsn)-1, j = (i+1):last(indsn)
if A[i,j] != transpose(A[j,i])
return false
Expand Down
10 changes: 10 additions & 0 deletions test/linalg/eigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ for eltya in (Float32, Float64, Complex64, Complex128, Int)
@test v == f[:vectors]
end
end

#test eigenvalue computations with NaNs
for eltya in (NaN16, NaN32, NaN)
@test_throws(ArgumentError, eig(fill(eltya, 1, 1)))
@test_throws(ArgumentError, eig(fill(eltya, 2, 2)))
test_matrix = rand(typeof(eltya),3,3)
test_matrix[2,2] = eltya
@test_throws(ArgumentError, eig(test_matrix))
end

# test a matrix larger than 140-by-140 for #14174
let aa = rand(200, 200)
for atype in ("Array", "SubArray")
Expand Down