Skip to content
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

gradient! allocates for matrices but not for vectors #698

Open
gdalle opened this issue Mar 25, 2024 · 0 comments
Open

gradient! allocates for matrices but not for vectors #698

gdalle opened this issue Mar 25, 2024 · 0 comments

Comments

@gdalle
Copy link
Member

gdalle commented Mar 25, 2024

Is it due to views?

julia> using ForwardDiff, Chairmarks

julia> g(x) = sum(abs2, x)
g (generic function with 1 method)

julia> @be (zeros(2), zeros(2), ForwardDiff.GradientConfig(g, zeros(2))) ForwardDiff.gradient!(_[1], g, _[2], _[3])
Benchmark: 3548 samples with 1255 evaluations
min    18.855 ns
median 19.215 ns
mean   19.753 ns
max    62.914 ns

julia> @be (zeros(2, 2), zeros(2, 2), ForwardDiff.GradientConfig(g, zeros(2, 2))) ForwardDiff.gradient!(_[1], g, _[2], _[3])
Benchmark: 2765 samples with 365 evaluations
min    67.745 ns (4 allocs: 160 bytes)
median 77.912 ns (4 allocs: 160 bytes)
mean   87.240 ns (4 allocs: 160 bytes)
max    220.408 ns (4 allocs: 160 bytes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant