-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Julia port of Openlibm expm1. #25903
Conversation
base/special/expm1.jl
Outdated
|
||
# filter out huge and non-finite argument | ||
if absx >= expm1_huge(T) # quit early for large absolute values of x | ||
if isinf(absx) |
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 indentation in this file is kind of all over the place. Should be 4-space indents everywhere.
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 will fix it. Not sure why that happened though...
I rebuilt with these functions, and am benchmarking against 0.6, but not seeing any difference. |
You're getting comparable timings? Edit: oh, I seem to be getting the exact same timings as well. Great, then I just need to polish this. |
base/special/expm1.jl
Outdated
# filter out huge and non-finite argument | ||
if absx >= expm1_huge(T) # quit early for large absolute values of x | ||
if isinf(absx) | ||
return xsign == true ? x : -T(1.0) |
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.
Probably just xsign
, not xsign == true
base/special/expm1.jl
Outdated
end | ||
else | ||
# k = round(Int32, expm1_invln2(T)*x) | ||
k = unsafe_trunc(Int32, expm1_invln2(T)*x + (!xsign ? 0.5 : -0.5)) |
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.
possibly ifelse(xsign, -0.5, 0.5)
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.
Also, T(0.5)
?
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.
to avoid the branch? and yes, T(0.5) to be safe!
@nanosoldier |
base/special/expm1.jl
Outdated
# the next line could be replaced with the above but we don't need the | ||
# safety of round, so we round by adding one half with the appropriate | ||
# sign and truncate to Int32 | ||
k = unsafe_trunc(Int32, expm1_invln2(T)*x + ifelse(xsign, -T(0.5), 0.5)) |
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.
T(0.5)
for the other branch too.
base/special/expm1.jl
Outdated
if k == -1 | ||
return T(0.5)*(x - e) - T(0.5) | ||
end | ||
if k ==1 |
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.
missing space
return T(1.0) + T(2.0)*(x - e) | ||
end | ||
end | ||
two_pow_k = expm1_two_pow_k(T, k) # T(2.0)^k but 9-10 times faster |
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.
Should this be merged into exp2
? Maybe we should have an exp2(T, x::Integer)
method.
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan |
can nansoldier run here again now that the benchmarks are tuned? @ararslan |
Yep, I recommend fixing the branch conflicts first though. |
@nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan |
CI seems unrelated as usual (it was a few sweet weeks of green CI we had :)) |
Nanosoldier can be activated again here. |
@nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan |
A few expm1 "regressions", but they might be flukes. Though, they're specific to Float32, so I'll have a look locally. |
Also, the new optimizer is enabled now. |
Comments for the PR in general or nanosoldier specifically ? @simonbyrne @stevengj |
It's likely because of the new optimizer - @Keno Probably shouldn't hold merging if all else is good, and we can have a new performance issue then. |
Can I turn the new optimizer off locally? Or is it no longer a flag on master? |
The flag should still work |
thanks, I'll try it without to see if that's why it regresses. |
I think this is good to go, unless @simonbyrne has some rewrites (though they could always be done later as well) |
@@ -0,0 +1,238 @@ | |||
# ==================================================== |
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.
Probably the comment should start with:
# This code is a Julia translation of the C code from ... with the following license:
to make it clear that this is not the original Sun code.
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.
Bump. |
Rebased on master. |
I can change the license comment as suggested by sgj when I get back from vacation, but if someone can push a commit with the changes before that, feel free. |
Fixed the license comment. Should we run nanosoldier here as well? |
@nanosoldier |
Nanosoldier is being weird. @nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan |
@simonbyrne thoughts on these benchmarks? |
base/math.jl
Outdated
@@ -277,7 +277,8 @@ asinh(x::Number) | |||
Accurately compute ``e^x-1``. | |||
""" | |||
expm1(x) | |||
for f in (:exp2, :expm1) | |||
|
|||
for f in (:exp2,) |
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.
Now that this is down to a single function, it would make sense to get rid of the loop.
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.
Yes, I should have made a comment after I did this. The only reason why I did it like this is because it was easier for me, and the remaining code will be removed when I rebase #24859 after this is merged. Both should be quite close to merge-able I think.
I can remove the loop in this PR if you prefer it for a "clean" git history.
(on a side note, having removed these functions from the tuple one by one, I'm very happy to see the loop gone soon :))
base/special/expm1.jl
Outdated
@@ -1,3 +1,4 @@ | |||
# This code is a Julia translation of the C code from ... with the following license: |
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 ...
should be replaced with the actual source(s) of the C code
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.
Ah, I actually saw that, but I was pretty sure I changed it. Lol
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.
Just double checked , we’re you commenting on an old commit?
Superseded by #37440 |
cc @simonbyrne
This works, but is a bit slower than the C version, and I'm not quite sure why.
I put the definitions in a module
JuLibm
, opened julia with-O3
punched inand got
https://gist.github.com/pkofod/c4dda880815985e6020ea58730d315cdhttps://gist.github.com/pkofod/d666951a7886f9f75ad013782b61acd9there will be tests, but I'm just posting this to get some feedback about what to look for. I have a feeling the problem here is the same one that is causing regressions here #24859
Design suggestions and comment suggestions are also very welcome!
and then we're golden