Skip to content

Commit

Permalink
Fix #263
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrebouchard committed Aug 13, 2024
1 parent 30d9565 commit 0dc2048
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/explorers/SliceSampler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/test_slice_sampler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0dc2048

Please sign in to comment.