Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 3394927

Browse files
committed
Avoid calling get() in the getArrays() method
1 parent e141d30 commit 3394927

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

python/tests/test_reports.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def test_get_spikes_from_population(self):
5151
dict_data = self.test_obj['All'].get_dict()
5252
self.assertTrue((dict_data["node_ids"] == np.asarray([5, 2, 3, 2, 3])).all())
5353
self.assertTrue((dict_data["timestamps"] == np.asarray([0.1, 0.2, 0.3, 0.7, 1.3])).all())
54-
dict_data_filtered = self.test_obj['All'].get_dict(node_ids=[5, 3])
55-
self.assertTrue((dict_data_filtered["node_ids"] == np.asarray([5, 3, 3])).all())
56-
self.assertTrue((dict_data_filtered["timestamps"] == np.asarray([0.1, 0.3, 1.3])).all())
54+
dict_data_filtered = self.test_obj['All'].get_dict(node_ids=[5, 3], tstart=0.2)
55+
self.assertTrue((dict_data_filtered["node_ids"] == np.asarray([3, 3])).all())
56+
self.assertTrue((dict_data_filtered["timestamps"] == np.asarray([0.3, 1.3])).all())
5757

5858
def test_getTimes_from_population(self):
5959
self.assertEqual(self.test_obj['All'].times, (0.1, 1.3))

src/report_reader.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,29 @@ SpikesArrays SpikeReader::Population::getArrays(const nonstd::optional<Selection
162162
return std::make_pair(node_ids_, timestamps_);
163163
}
164164

165-
auto spikes = get(node_ids, tstart, tstop);
166-
167-
std::vector<NodeID> nodeids;
168-
std::vector<double> timestamps;
169-
for (const auto& pair : spikes) {
170-
nodeids.push_back(pair.first);
171-
timestamps.push_back(pair.second);
165+
SpikesArrays arrays;
166+
const auto& node_ids_selection = node_ids.value().flatten();
167+
// Create arrays directly for required data based on conditions
168+
for (size_t i = 0; i < node_ids_.size(); ++i) {
169+
const auto& node_id = node_ids_[i];
170+
const auto& timestamp = timestamps_[i];
171+
172+
// Check if node_id is found in node_ids_selection
173+
bool node_ids_found = std::find(node_ids_selection.begin(),
174+
node_ids_selection.end(),
175+
node_id) != node_ids_selection.end();
176+
177+
// Check if timestamp is within valid range
178+
bool valid_timestamp = (!tstart || timestamp >= tstart.value()) &&
179+
(!tstop || timestamp <= tstop.value());
180+
181+
// Include data if both conditions are satisfied
182+
if (node_ids && node_ids_found && valid_timestamp) {
183+
arrays.first.push_back(node_id);
184+
arrays.second.push_back(timestamp);
185+
}
172186
}
173-
174-
return std::make_pair(nodeids, timestamps);
187+
return arrays;
175188
}
176189

177190
SpikeReader::Population::Sorting SpikeReader::Population::getSorting() const {

0 commit comments

Comments
 (0)