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:
With this PR, the inner sampling function for CirculantEmbedding is completely non-allocating. See this benchmark script:
Output
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: