JuliaDiff / ChainRules.jl

forward and reverse mode automatic differentiation primitives for Julia Base + StdLibs
Other
435 stars 89 forks source link

Remove closures for callable types #657

Open ChrisRackauckas opened 2 years ago

ChrisRackauckas commented 2 years ago

Because closures are not consistent types, they inhibit precompilation. If the closures used for the adjoints were instead callable types, which would make sure that every session has the same types and thus they should in theory be amenable to precompilation. This would be a huge but non-breaking code churn. I wonder if everyone would be okay with that programming style. It would also help in many cases with inference, because closures are known to cause inference issues. So in general this could improve compile and run time performance quite a bit, but it's a bit nasty.

oxinabox commented 2 years ago

This is so much code churn and would i think significantly inhibit readability. Julia itself should be improved to be able to handle these cases better.

If it doesn't we should bare this in mind for the ChainRulesCore 2.x timeframe.

gdalle commented 1 year ago

Is it a good idea to code our own custom chain rules that way though?