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

Conversation

mcognetta
Copy link
Contributor

@mcognetta mcognetta commented Sep 15, 2016

Added a check when computing the eigenvalue of a matrix for if the matrix is a 1x1 matrix with NaN elements. Previously this case incorrectly returned a value (not NaN) while the 2x2 and larger dimensional cases threw an error.

This is my first contribution to Julia, so any help or feedback is greatly appreciated.

#18267

@mcognetta mcognetta changed the title 18267 null matrix eigenvalue 18267 1x1 NaN matrix eigenvalue Sep 15, 2016
@andreasnoack
Copy link
Member

I think the problem is the issymmetric function. It shouldn't return true for the 1x1 case when the value is NaN. I think the right fix shoud be to also test the diagonal in https://github.com/JuliaLang/julia/blob/master/base/linalg/generic.jl#L702

@KristofferC
Copy link
Sponsor Member

How about issymmetric(NaN)?

@mcognetta
Copy link
Contributor Author

I am not so sure about the 1x1 issymmetrical case. It is the "same" NaN when transposed so maybe it isn't incorrect for it to be considered symmetrical.

Anyway, I can redo it to be checked in the issymmetric function if that is deemed the better solution (obviously you guys know better than me).

@andreasnoack
Copy link
Member

Symmetry is A[i,j] == A[j,i] for all i,j so we just inherit the behavior. The definition for Number should be changed to

issymmetric(x::Number) = x == x

@mcognetta
Copy link
Contributor Author

I updated it. I did not realize that Julia didn't evaluate NaN == NaN in any case.

I am going to submit a new pr for the issymmetric(x::Number) = x == x since that probably shouldn't be looped in here.

By the way, I know about methods() and applicable(), but is there a way to tell, given a multiple dispatch method name and a possible input, which method specifically would be called (the line number and the parameter types/function signature)? When I was trying to determine which issymmetric and eigfact! was being called, I had to resort to putting print statements in every candidate and rebuilding, which was inefficient.

@kshyatt kshyatt added the domain:linear algebra Linear algebra label Sep 15, 2016
@simonster
Copy link
Member

By the way, I know about methods() and applicable(), but is there a way to tell, given a multiple dispatch method name and a possible input, which method specifically would be called (the line number and the parameter types/function signature)? When I was trying to determine which issymmetric and eigfact! was being called, I had to resort to putting print statements in every candidate and rebuilding, which was inefficient.

Try @which f(x) (or @edit f(x) if you want to open it in your editor)

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(3,3)
Copy link
Contributor

@tkelman tkelman Sep 18, 2016

Choose a reason for hiding this comment

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

probably rand(eltya, 3, 3) rand(typeof(eltya), 3, 3) to avoid repeating this for Float64 3 times?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I did not consider this behavior. Thanks.

@@ -100,7 +100,7 @@ end
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(3,3)
test_matrix = rand(typeof(eltya,3,3)
Copy link
Contributor

Choose a reason for hiding this comment

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

missing a close paren

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.

@andreasnoack
Copy link
Member

@mcognetta It would be great to get this merged soon. Do you have time to finish up the PR?

@mcognetta
Copy link
Contributor Author

Sorry, been a little busy. Ill do it now.

@andreasnoack
Copy link
Member

Thanks for fixing this.

@andreasnoack andreasnoack merged commit 2042ee6 into JuliaLang:master Sep 27, 2016
@mcognetta
Copy link
Contributor Author

Thanks for the help.

@mcognetta mcognetta deleted the 18267_null_matrix_eigenvalue branch September 28, 2016 03:54
@andreasnoack andreasnoack mentioned this pull request Oct 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants