Skip to content
Snippets Groups Projects
Commit 1bd65e13 authored by Wouter Klijn's avatar Wouter Klijn Committed by Ben Cumming
Browse files

410 rss cell bug (#411)

Fix bug in `rss_cell_group`s with more than one cell with different `dt` or `start_time` values.
Fixes #410.
parent 6eeba7f0
No related branches found
No related tags found
No related merge requests found
......@@ -29,22 +29,27 @@ public:
void reset() override {
clear_spikes();
time_ = 0;
for (auto& cell : cells_) {
cell.step = 0;
}
}
void set_binning_policy(binning_kind policy, time_type bin_interval) override {}
void advance(epoch ep, time_type dt, const event_lane_subrange& events) override {
for (const auto& cell: cells_) {
auto t = std::max(cell.start_time, time_);
for (auto& cell: cells_) {
auto t_end = std::min(cell.stop_time, ep.tfinal);
auto t = cell.start_time + cell.step*cell.period;
while (t < t_end) {
spikes_.push_back({{cell.gid, 0}, t});
t += cell.period;
// Increasing time with period time step has float issues
++cell.step;
t = cell.start_time + cell.step*cell.period;
}
}
time_ = ep.tfinal;
}
const std::vector<spike>& spikes() const override {
......@@ -71,13 +76,15 @@ private:
{}
cell_gid_type gid;
// We do not store the time but a count of the number of step since start
// of cell. This prevents float problems at high number.
std::size_t step;
};
// RSS cell descriptions.
std::vector<rss_info> cells_;
// Simulation time for all RSS cells in the group.
time_type time_;
// Spikes that are generated.
std::vector<spike> spikes_;
......
......@@ -62,6 +62,22 @@ TEST(rss_cell, poll_time_after_end_time)
EXPECT_EQ(12u, sut.spikes().size());
}
TEST(rss_cell, rate_bigger_then_epoch)
{
constexpr time_type dt = 0.01; // dt is ignored by rss_cell_group::advance().
rss_cell desc{ 0.0, 100.0, 1000.0 };
rss_cell_group sut({ 0 }, rss_recipe(1u, desc));
// take time steps of 10 ms
for (time_type start = 0.0; start < 1000.0; start += 10) {
sut.advance(epoch(start, start + 10.0), dt, {});
}
// We spike once every 100 ms so in 1000.0 ms we should have 10
EXPECT_EQ(10u, sut.spikes().size());
}
TEST(rss_cell, cell_kind_correct)
{
rss_cell desc{0.1, 0.01, 0.2};
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment