JuliaStats / Distributions.jl

A Julia package for probability distributions and associated functions.
Other
1.08k stars 410 forks source link

Allocations when generating samples from MvNormal with full covariance matrix #1790

Open FelixNoessler opened 8 months ago

FelixNoessler commented 8 months ago

Hello,

thanks for creating the Distributions package!

I get 16 allocations when I want to generate random samples from a MvNormal with full covariance matrix. Apparently, there is also type instability problem. Is there a way to generate random samples with full covariance matrix without allocations?

Best, Felix

using Distributions
using Random

d = MvNormal([1.0, 1.0], [1.0 0.5; 0.5 1.0])
u = Array{Float64}(undef, 2)
@allocated rand!(d, u)
@profview_allocs rand!(d, u) sample_rate = 1

image