using AdaptiveRejectionSampling: ARSampler, Objective, sample!
using DifferentiationInterface, Distributions
using ForwardDiff
using Mooncake
using Enzyme
using Chairmarks
# Define function to sample from
f(x) = logpdf(Laplace(0., 0.5), x) + logpdf(Normal(0.0, 2.0), x)
const sam_forwarddiff = ARSampler(Objective(f), (-Inf, Inf), [-0.5, 0.5])
@be deepcopy(sam_forwarddiff) sample!(_, 100000, max_segments = 25) samples=100 evals=1 seconds=1000
Benchmark: 100 samples with 1 evaluation
min 8.915 ms (3 allocs: 781.320 KiB)
median 9.168 ms (3 allocs: 781.320 KiB)
mean 10.138 ms (3.21 allocs: 781.576 KiB, 0.91% gc time)
max 104.300 ms (6 allocs: 784.977 KiB, 90.84% gc time)
sam_mooncake = ARSampler(Objective(f; adbackend = AutoMooncake()), (-Inf, Inf), [-0.5, 0.5])
@be deepcopy(sam_mooncake) sample!(_, 100000, max_segments = 25) samples=100 evals=1 seconds=1000
Benchmark: 100 samples with 1 evaluation
min 8.826 ms (3 allocs: 781.320 KiB)
median 9.110 ms (3 allocs: 781.320 KiB)
mean 9.456 ms (3.18 allocs: 781.540 KiB, 1.22% gc time)
max 31.420 ms (6 allocs: 784.977 KiB, 69.88% gc time)
sam_mooncake = ARSampler(Objective(f; adbackend = AutoEnzyme()), (-Inf, Inf), [-0.5, 0.5])
@be deepcopy(sam_mooncake) sample!(_, 100000, max_segments = 25) samples=100 evals=1 seconds=1000
Benchmark: 100 samples with 1 evaluation
min 8.850 ms (3 allocs: 781.320 KiB)
median 9.195 ms (3 allocs: 781.320 KiB)
mean 9.783 ms (3.18 allocs: 781.540 KiB, 1.46% gc time)
max 48.349 ms (6 allocs: 784.977 KiB, 80.06% gc time)