JuliaMath / JuliaMath/MeasureTheory.jl

`logdensityof(::For, x)` slower than it should be

Open
#243 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
401
Forks
31
PR merge metrics
No merged PRs in 30d

Description

Say we have
```julia
using MeasureTheory, BenchmarkTools

m = For(1:1000) do j
Normal(μ=j)
end

x = rand(m)
```

Then compare
```julia
julia> @btime logdensityof($m, $x)
3.114 μs (0 allocations: 0 bytes)
-1414.4176763297564

julia> @btime sum(j -> logdensityof(Normal(μ=j), $x[j]), 1:1000)
684.154 ns (0 allocations: 0 bytes)
-1414.4176763297567
```

The `For` should be faster, because it knows about the common base measure. What's going on here?

Note that "slowness" is only relative to another approach *in MeasureTheory*. We're still well ahead of Distributions:
```julia
julia> @btime sum(j -> logdensityof(Dists.Normal(j, 1), $x[j]), 1:1000)
7.166 μs (0 allocations: 0 bytes)
-1414.4176763297567
```

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.