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

specialize on input function on a few more wrapper functions #315

Merged
merged 1 commit into from
Apr 6, 2018

Conversation

KristofferC
Copy link
Collaborator

@KristofferC KristofferC commented Apr 4, 2018

Benchmark

using ForwardDiff
using BenchmarkTools

function run0(x, f, n)
    out = similar(x);
    cfg = ForwardDiff.GradientConfig(f, x, ForwardDiff.Chunk{5}());
    for i = 1:n
        ForwardDiff.gradient!(out, f, x, cfg);
    end
    return out
end

V(x) = (dot(x,x)-1)^2;

x5 = rand(5);

@btime run0(x5, V, 100);

Before:

  42.694 μs (103 allocations: 6.92 KiB)

After:

  10.979 μs (3 allocations: 688 bytes)

Ref: https://discourse.julialang.org/t/forwarddiff-and-gradientconfig-memory-usage/10145/2.
Arguably, StaticArrays should have been used for this size but perhaps this is still worth it.
Same "issue" might exist for derivatives / jacobians etc.

@simonbyrne
Copy link
Contributor

Wait, specialization is affected by the existence of type parameters in method definitions?

@ChrisRackauckas
Copy link
Member

ChrisRackauckas commented Apr 5, 2018

Wait, specialization is affected by the existence of type parameters in method definitions?

Only for functions IIRC (and Datatype has their own exception). I really don't like this exception...

@simonbyrne
Copy link
Contributor

Is it documented anywhere?

@ChrisRackauckas
Copy link
Member

JuliaLang/julia#19137

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

Successfully merging this pull request may close these issues.

4 participants