Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions include/sampleflow/filters/take_every_nth.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,14 +138,16 @@ namespace SampleFlow
{
std::lock_guard<std::mutex> lock(mutex);

++counter;
if (counter % every_nth == 0)
{
counter = 0;
counter = 1;
return {{ std::move(sample), std::move(aux_data)}};
}
else
return {};
{
++counter;
return {};
}
}

}
Expand Down
9 changes: 5 additions & 4 deletions tests/every_nth_01.output
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
2
4
6
8
1
3
5
7
9
Loading