JuliaDiff/ForwardDiff.jl

`gradient!` allocates for matrices but not for vectors

gdalle opened this issue · 0 comments

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)