From 0dc20489b9487436b8bef3cfb4a6d7ef58a03775 Mon Sep 17 00:00:00 2001 From: Alexandre Bouchard Date: Tue, 13 Aug 2024 11:17:53 -0700 Subject: [PATCH] Fix #263 --- src/explorers/SliceSampler.jl | 1 + test/test_slice_sampler.jl | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/explorers/SliceSampler.jl b/src/explorers/SliceSampler.jl index 878169795..1a940e732 100644 --- a/src/explorers/SliceSampler.jl +++ b/src/explorers/SliceSampler.jl @@ -134,6 +134,7 @@ end # handle integers separately function initialize_slice_endpoints(current::T, width, rng) where {T<:Integer} + @assert isinteger(width) "for integer variables, the width should be an integer. Got: $width" width = ceil(T, width) L = current - rand(rng, 0:width) R = L + width diff --git a/test/test_slice_sampler.jl b/test/test_slice_sampler.jl index 89461c094..274a0d2b2 100644 --- a/test/test_slice_sampler.jl +++ b/test/test_slice_sampler.jl @@ -104,3 +104,17 @@ end @testset "SliceSampler" begin test_slice_sampler() end + + +DynamicPPL.@model function test() + p ~ Categorical(0.1*ones(10)) +end + + +@testset "Bad width" begin + test_target = TuringLogPotential(test()) + inputs = Inputs(target = test_target, + explorer = SliceSampler(w = 0.1, p = 20, n_passes = 1, max_iter = 1_024) + ) + @test_throws "AssertionError: for integer variables, the width should be an integer. Got: 0.1" pt = pigeons(inputs) +end \ No newline at end of file