JuliaMath / JuliaMath/MeasureBase.jl

Add specialize `logdensityof` directly where applicable?

Open
#59 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
32
Forks
4
PR merge metrics
No merged PRs in 30d

Description

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

```julia
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%
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.