-
-
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
exp() accuracy is severly affected when using --fast-mode=fast #41592
Comments
There's a couple of open issues about just getting rid of math-mode=fast, this issue is more likely to reinforce that position than anything else. To save math-mode=fast, we'd need a better way of doing this type of hacks. Something like a |
Not as bad as julia> x = randn(10)'
1×10 adjoint(::Vector{Float64}) with eltype Float64:
0.411952 -1.20621 -0.780723 0.69826 -1.60801 -1.88011 0.363784 0.663141 -0.874339 0.613377
julia> sinpi.(x)
1×10 Matrix{Float64}:
0.0 -0.0 -0.0 0.0 -0.0 -0.0 0.0 0.0 -0.0 0.0
julia> cospi.(x)
1×10 Matrix{Float64}:
1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
That's a hack to round quickly over the range of numbers for which |
I believe it's that the compiler might constant fold a call to e.g. I'm not sure this issue is really valid. There is no "spec" for what constitutes an acceptable result under fast-math, and no way to implement such a spec either. |
Closed by #41638 |
As discussed on the forum, the accuracy of exp() suffers when using fast-math because llvm optimizes away a numerical trick that is used for rounding:
https://discourse.julialang.org/t/whats-going-on-with-exp-and-math-mode-fast/64619/21
While some inaccuracy is expected when using fast-math, it seems like this specific situation could be improved by instructing llvm to not optimize away the numerical rounding trick.
There's probably a better way to do this, but I was able to get exp() working with fast-math by replacing the subtraction:
N_float -= MAGIC_ROUND_CONST(T)
with
N_float = forcesub(N_float, MAGIC_ROUND_CONST(T))
where
Before (with --math-mode=fast):
After (with --math-mode=fast):
The text was updated successfully, but these errors were encountered: