Skip to content

Add specialize logdensityof directly where applicable? #59

@oschulz

Description

@oschulz

In some cases, we'd gain performance by specializing logdensityof directly:

julia> direct_logdensityof(::StdNormal, x) = - muladd(x, x, log2π) / 2;

julia> m = StdNormal();

julia> X = rand(m^1000); Y = similar(X);

julia> @benchmark broadcast!(logdensityof, $Y, $(Ref(m)), $X)
BenchmarkTools.Trial: 10000 samples with 864 evaluations.
 Range (min  max):  137.241 ns  364.372 ns  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     166.777 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   169.626 ns ±   7.933 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

julia> @benchmark broadcast!(direct_logdensityof, $Y, $(Ref(m)), $X)
BenchmarkTools.Trial: 10000 samples with 967 evaluations.
 Range (min  max):   82.804 ns  453.609 ns  ┊ GC (min  max): 0.00%  0.00%
 Time  (median):     106.885 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   108.045 ns ±  12.766 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

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