-
Notifications
You must be signed in to change notification settings - Fork 150
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
(RFC) fix eigen in the diagonal 2x2-case #524
Conversation
Yes, I'm guessing for
This code is for |
Thanks, @andyferris . I just checked |
Unrelated to the bugfix, but the codepath for
which reduced the code duplication quite a lot. |
Yes, I was aware of that. I wasn't sure about the original intention to have that code duplication, so I felt it must have been something beyond my understanding of compiler functionality (which is very low). I'll use @fredrikekre's version then. |
It was just a suggestion, since code duplication can often lead to bugs. I should perhaps have benchmarked first: StaticArrays master results in |
This reverts commit 97984cf.
Hm, on my machine (tested on a |
src/eigen.jl
Outdated
@@ -136,7 +136,7 @@ end | |||
TA = eltype(A) | |||
|
|||
@inbounds if A.uplo == 'U' | |||
if a[3] == 0 # A is diagonal | |||
if a[3] == zero(TA) # A is diagonal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this ever needed? You can compare with 0, won't that work fine? For example no need to create a zero(DualNumber)
if the type is a dual number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it depends on what is cheaper: converting 0
to a comparable type or constructing the zero element. I just tested one versus the other, and for Float
it doesn't make any difference (in contrast to my minor improvement above), but for Dual
the comparison == zero(Dual)
is indeed more expensive than == 0
. I guess I'll revert the last commit then?
I added some tests, we can refactor the code some other time, but it is good to get in the bugfix ASAP |
Fixes #523. I also reduced the amount of
@inbounds
by tearing it to the outside. I think it should apply everywhere in the following block.Some questions:
T
equal toeltype(A)
?TA(1)
,TA(0)
andone(TA)
,zero(TA)
?TODO: add tests for the diagonal 2x2 case.