Skip to content

Commit

Permalink
add test for callback without predetermined N
Browse files Browse the repository at this point in the history
  • Loading branch information
mileslucas committed Apr 10, 2021
1 parent a129187 commit a182954
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,16 @@

@testset "Testing callbacks" begin
function count_iterations(rng, model, sampler, sample, state, i; iter_array, kwargs...)
iter_array[i] = i
push!(iter_array, i)
end
N = 100
it_array = zeros(N)
it_array = Float64[]
sample(MyModel(), MySampler(), N; callback=count_iterations, iter_array=it_array)
@test it_array == collect(1:N)

# sampling without predetermined N
it_array = Float64[]
chain = sample(MyModel(), MySampler(); callback=count_iterations, iter_array=it_array)
@test it_array == collect(1:size(chain, 1))
end
end

0 comments on commit a182954

Please sign in to comment.