WIP/RFC optionally use faster cache #99
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a very early WIP that is more a proof of concept and it would be nice with some comments before I continue.
In #92 I noticed that the dict used to cache arrays is sometimes a bit slow. There are many levels of indirections, an anonymous function -> double key lookup in a dict to get back maybe an array of size 10. The point of this PR would be that a user could optionally declare input size + input type when creating the function that computes the derivative. If this is done, we know the exact data types and sizes that are needed and can therefore use a specialized type to cache the arrays instead of the dict method. This can lead to significantly faster run times.
Right now, what is implemented is an extra method to
gradient
where the input size and input type is used. A new cacheGradientCache
is then used instead ofForwardDiffCache
.For a quite simple function of size 10, this gives about a 2x speedup (benchmarked on 0.4.3).
What would be left to do is:
cache
is no longer concrete.gradient
functionNote, as I said, this is mostly a proof of concept to get the ball going. If you (@jrevels) had somethins else in mind that you want to go with, feel free to do that.