-
Notifications
You must be signed in to change notification settings - Fork 150
Add specialized StaticArrays-based methods #215
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
Conversation
Is this expected? The speedup for
This PR sounds really useful for tools like Optim on low-dimensional functions, both because of the potential differentiation speedup, and because returning the gradient as an |
Yes, this is expected. The main benefit of Note this extraction process is not unrolled like it is for |
Just added some special cases for Hessians as well: julia> x = rand(3, 3);
julia> sx = SArray{Tuple{3, 3}}(x);
julia> out = similar(x, 9, 9);
julia> cfg = ForwardDiff.HessianConfig(prod, x);
# naive old method
julia> @btime ForwardDiff.hessian(prod, $x);
37.159 μs (17 allocations: 17.11 KiB)
# almost non-allocating old method
julia> @btime ForwardDiff.hessian!($out, prod, $x, $cfg);
2.115 μs (2 allocations: 832 bytes)
# stack-allocated new method
julia> @btime ForwardDiff.hessian(prod, $sx);
1.220 μs (0 allocations: 0 bytes) |
Tests pass locally, and everything here is ready. However, I developed this against StaticArrays master, so this PR is now waiting on JuliaArrays/StaticArrays.jl#142. |
Argh, 32 bit Windows...AppVeyor was passing before this PR, and it seems like this PR doesn't touch the code that would cause that test to fail, so I'm not sure what's going on here. |
@@ -1,6 +1,5 @@ | |||
environment: | |||
matrix: | |||
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cutting the Gordian knot.
Adds StaticArrays as dependency, and uses it to support a low-dimensional, stack-allocated differentiation API.
Currently, I've only added support for gradients and Jacobians. EDIT: Added special cases for Hessians as well, see below.
I still need to add back in the tests I originally used in #213.Done.