diff --git a/include/sampleflow/filters/take_every_nth.h b/include/sampleflow/filters/take_every_nth.h index 3bb790b..14681f4 100644 --- a/include/sampleflow/filters/take_every_nth.h +++ b/include/sampleflow/filters/take_every_nth.h @@ -27,7 +27,8 @@ namespace SampleFlow { /** * An implementation of the Filter interface in which every $n$th sample - * is passed on and all other samples are simply discarded. This filter + * (including the zeroth, i.e., initial sample) is passed on + * and all other samples are simply discarded. This filter * is useful to reduce the amount of data produced by a sampling * algorithm. This is often warranted in Markov Chain sampling algorithms * in which samples are highly correlated and consequently not every sample @@ -137,14 +138,16 @@ namespace SampleFlow { std::lock_guard lock(mutex); - ++counter; if (counter % every_nth == 0) { - counter = 0; + counter = 1; return {{ std::move(sample), std::move(aux_data)}}; } else - return {}; + { + ++counter; + return {}; + } } } diff --git a/tests/every_nth_01.output b/tests/every_nth_01.output index 628d2a8..2738e8e 100644 --- a/tests/every_nth_01.output +++ b/tests/every_nth_01.output @@ -1,4 +1,5 @@ -2 -4 -6 -8 +1 +3 +5 +7 +9