Skip to content

gradient! allocates for matrices but not for vectors #698

Open
@gdalle

Description

@gdalle

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions