PieterjanRobbe / GaussianRandomFields.jl

A package for Gaussian random field generation in Julia
Other
66 stars 11 forks source link

Completely non-allocating sampling function for `CirculantEmbedding` #23

Closed giordano closed 4 years ago

giordano commented 4 years ago

With this PR, the inner sampling function for CirculantEmbedding is completely non-allocating. See this benchmark script:

using GaussianRandomFields, BenchmarkTools

x = 1.:200.
y = 1.:200.
dim = 2
lambda = 1.00
nu = 2.5
sigma = 1.0
cov = CovarianceFunction(dim, Matern(lambda, nu, σ = sigma))
grf = GaussianRandomField(cov, CirculantEmbedding(), x, y, minpadding = 0)
v = grf.data[1]
rnn = randn(size(v))

@info "High-level sampling function"
@btime GaussianRandomFields.sample($grf, xi = $rnn)

w = Matrix{ComplexF64}(undef, size(v))
z = Array{eltype(grf.cov)}(undef, length.(grf.pts))
@info "Inner sampling function"
@btime GaussianRandomFields._sample!($w, $z, $grf, $rnn)

Output

[ Info: High-level sampling function
  2.584 ms (5 allocations: 4.31 MiB)
[ Info: Inner sampling function
  2.462 ms (0 allocations: 0 bytes)

The speedup is modest because the FFT is the bottleneck, but being able to call a function that doesn't allocate allows us to bring allocations down in a computational intensive loop.

Fix #22.

Can we please have a new release after this is merged? :slightly_smiling_face:

coveralls commented 4 years ago

Pull Request Test Coverage Report for Build 61


Totals Coverage Status
Change from base Build 60: 0.05%
Covered Lines: 418
Relevant Lines: 474

💛 - Coveralls