diff --git a/src/rss_cell_group.hpp b/src/rss_cell_group.hpp index f9e292962714b118525ef217143e60f4a8d8a8cb..575085fccc22c9935a231b24b9dc87da14cdd608 100644 --- a/src/rss_cell_group.hpp +++ b/src/rss_cell_group.hpp @@ -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_; diff --git a/tests/unit/test_rss_cell.cpp b/tests/unit/test_rss_cell.cpp index 4b0b648c0f54c025b639068b5e8afa05b0ce1c23..f8c545a1cdd7ad7506ca6fb59b9e7c6270a72908 100644 --- a/tests/unit/test_rss_cell.cpp +++ b/tests/unit/test_rss_cell.cpp @@ -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};