-
Notifications
You must be signed in to change notification settings - Fork 146
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
wip: implement macro for users to define their own derivatives #165
base: master
Are you sure you want to change the base?
wip: implement macro for users to define their own derivatives #165
Conversation
A bit blocked here due to https://discourse.julialang.org/t/question-about-scoping-inside-a-function/709/12 |
I am thinking of using something like this in https://github.com/KristofferC/ContMechTensors.jl. I could basically define a bunch of known derivatives (like |
95a407b
to
07cd718
Compare
Benchmarks at https://gist.github.com/KristofferC/930dc1de9d64a6930d3f3c81da72cae4. The user defined functions are non allocating but consistently slower. The reason for this (I believe) is that the function turns into
Edit: Boxes are not the only thing, they are a bit slower in global scope as well. However, the extraction of the jacobian and calling to blas might explain that. The scalar derivatives are the same speed in global scope. |
@KristofferC It seems the only item on your checklist is the docs, but is the main blocker here still the closure performance bug? If so, that can usually be avoided by explicitly using a callable type instead (I know it's annoying, though). I'm curious because I'm excited for this feature, let me know if there's any way for me to help 😃 |
The most helpful thing would be to read the docs I have written, comment on that and try the macro out for yourself to see how you think the workflow is. I actually don't think the closure thing is a big problem. The reason these manual implementations are slower sometimes is that the matrix multiplication (in case of jacobians) that is being done to propagate the partials could very well be more expensive than to just evaluate the function with dual numbers. |
07cd718
to
d27dd78
Compare
Rebased |
Is this progressing? My version of ForwardDiff does not implement these macros and Icoudl really use it :-) |
bump 😄 |
This is a start towards an official API for fixing #89. It provides macros for derivatives, gradients and jacobians such that user defined derivatives are easily injected:
For gradients and jacobians there are two "config" objects that can be used, which cache intermediate arrays needed.
I don't think we can support user defined Hessians at the moment because of the composition of gradient and jacobian that is currently being used.
TODOs:
I opened a thread on the forum: https://discourse.julialang.org/t/question-about-scoping-inside-a-function/709
Conclusion Lowering bug in julia 0.5. Need to define the derivative before the function.