Open
Description
Problem
Consider the following minimal example.
using LinearAlgebra, Random, Distributions, BenchmarkTools, Test
samples = randn(5, 1000)
dist = MvNormal(zeros(5), I)
function mod_logpdf(dist, samples)
out = Array{Float64}(undef, size(samples, 2))
logpdf!(out, dist, samples)
end
julia> @test logpdf(dist, samples) ≈ mod_logpdf(dist, samples)
Test Passed
julia> @btime logpdf($dist, $samples);
89.290 μs (1001 allocations: 101.69 KiB)
julia> @btime mod_logpdf($dist, $samples);
12.672 μs (3 allocations: 47.05 KiB)
logpdf
is around 7x slower than mod_logpdf
, even though they both do exactly the same thing.
Possible solution
Add a method
logpdf(d::AbstractMvNormal, x::AbstractMatrix{<:Real})
that does something like mod_logpdf
.
Metadata
Metadata
Assignees
Labels
No labels