Skip to content

Commit a182954

Browse files
committed
add test for callback without predetermined N
1 parent a129187 commit a182954

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

test/sample.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,16 @@
292292

293293
@testset "Testing callbacks" begin
294294
function count_iterations(rng, model, sampler, sample, state, i; iter_array, kwargs...)
295-
iter_array[i] = i
295+
push!(iter_array, i)
296296
end
297297
N = 100
298-
it_array = zeros(N)
298+
it_array = Float64[]
299299
sample(MyModel(), MySampler(), N; callback=count_iterations, iter_array=it_array)
300300
@test it_array == collect(1:N)
301+
302+
# sampling without predetermined N
303+
it_array = Float64[]
304+
chain = sample(MyModel(), MySampler(); callback=count_iterations, iter_array=it_array)
305+
@test it_array == collect(1:size(chain, 1))
301306
end
302307
end

0 commit comments

Comments
 (0)