-
Notifications
You must be signed in to change notification settings - Fork 147
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
Specialized math functions for use with Duals? #148
Comments
More specialized methods for It would be nice to have a |
See also JuliaLang/julia#10442 |
Agree that it would be better if it could be supplied as an overload to a function in Base. I remember looking into that a little bit. As I understand it, FSINCOS is an 387 instruction, but is slower than separately computing sin and cos using SSE instructions. |
Based on what I saw in JuliaLang/julia#10442, I feel I must update my draft implementation: @inline sincos(x) = (sin(x), cos(x))
@inline function sincos(x::Dual)
sx, cx = sincos(value(x))
return (
Dual(sx, cx * partials(x)),
Dual(cx, -sx * partials(x)),
)
end Now, if |
I was examining some trig code with Dual values using
@code_llvm
and@code_native
, and noticed that the generated code included redundant calls tosin(x)
andcos(x)
; this derivative could be coded more optimally.In my case, the function evaluates both
sin
andcos
of several input variables. However, I can take advantage of this fact when using Duals, by creating a specializedsincos
function:I understand ForwardDiff already implements a similar optimization in the case of
exp
, for example. I'm not really pushing this as a must-have addition (though not opposed if others think it's good). What I'm really curious to know is if this sort of specialized math function + optimization has other similar use cases and whether it makes sense for other users.Footnote: I didn't notice a significant runtime improvement from implementing this is my code, so, in my case the idea may be a dud. (Or I may have too much overhead from other sources.)
The text was updated successfully, but these errors were encountered: