-
Notifications
You must be signed in to change notification settings - Fork 22
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
log1pexp(x) when x < -37 #13
Comments
I can see how your version will be faster because it avoids the log1pexp_v2(x::Number) = log1pexp_v2(float(x)) to get coverage for integer arguments. |
I would do |
You're right. That's better. |
Should I prepare a PR on this? |
Yes, please. |
@dmbates Please see JuliaStats/StatsFuns.jl#70 |
If I may ask, what's the current state of this? |
I don't know, I just transferred the issue when |
JuliaStats/StatsFuns.jl#70 was just closed, but a PR here is welcome. |
I'll do a PR right after #35 is done. |
Great, thanks! |
I was reading R's implementation of
log1pexp
and they include one additional branch (see https://cran.r-project.org/web/packages/Rmpfr/vignettes/log1mexp-note.pdf, equation 10).Currently StatsFuns does this:
https://github.com/JuliaStats/StatsFuns.jl/blob/ae40bc1c6ee63a5624ba6cd168da5bf43f473e59/src/basicfuns.jl#L66
Whereas including the additional branch it would be:
Apparently including the
x < -37.
check reduces the function's computation time by 25% (because it saves the call tolog1p
I guess). But I am no expert doing this kind of performance tests so please can someone else more knowledgeable check this? Here is the test I did:Both
log1pexp_v2
andlog1pexp
give numerically identical results.If this is worth it I can prepare a PR.
Update: Actually it seems much of the time is due to the
oftype(exp(-x), x)
bit in the final branch. I think specializing onAbstractFloat
would take care of that. Even after this change thex ≤ -37.
check is faster.The text was updated successfully, but these errors were encountered: