-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unnecessary and slow hypot calls in real givensAlgorithm. Add …
…copyright statement.
- Loading branch information
1 parent
ed97120
commit 17abcd9
Showing
1 changed file
with
15 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17abcd9
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.
hypot has better handling for the case where x^2 overflows. Do we care?
17abcd9
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.
The algorithm checks for overflow and scales the arguments if necessary and therefore the use of
hypot
is unnecessary.17abcd9
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.
Weird, last week I replaced
sqrt(a*a + b*b)
withhypot(a, b)
in my own code because my tests (Float64
only) showed it was faster as well. Maybe I have to revisit that...17abcd9
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 found the same thing in
Images.jl
previously. @andreasnoack, do you have some benchmark data which shows this speed improvement?17abcd9
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.
so approximately 20 times faster than
hypot
on my machine.17abcd9
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.
Thanks. Would replacing the hypot function be worthwhile (keeping @vtjnash's comment about overflow handling in mind)?
17abcd9
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 don't think that replacing
hypot
is right. It is probably the best you can do if you want to avoid under- and overflow. The problem here is thatgivensAlgorithm
is doing the same checks ashypot
so the checks are done twice.I've looked a bit more on this and I think we could just use a simple function with
hypot
instead the long version borrowed from LAPACK which basically includes an implementationhypot
. I'll take another look atOn computing Givens rotations reliably and efficiently
and then probably open a pull request with a new shorter and faster real
givensAlgorithm
.