JuliaAttic / ReverseDiffSource.jl

Reverse automated differentiation from source
MIT License
47 stars 12 forks source link

Pre-allocate memory for derivatives ? #36

Closed jeff-regier closed 8 years ago

jeff-regier commented 8 years ago

Is there a way to pre-allocate an array to store derivatives, and have ReverseDiffSource write derivatives to that array, rather than allocating new memory at every call?

fredo-dedup commented 8 years ago

The only way I can think of is to use the rdiff method working on expressions (not the one working on functions) and edit the generated expression (replacing the dx = zeros(..) with fill!(dx,0.) ), dx being the preallocated variable. If you want to wrap the resulting expression in a function you can either create dx in a closure around the function or require the user to pass it in the function arguments.

jeff-regier commented 8 years ago

I'll do that. Thanks for the suggestion!