Skip to content

Commit

Permalink
Performance improvement for handling subgroups in push_spikes using b…
Browse files Browse the repository at this point in the history
…isect.
  • Loading branch information
Marcel Stimberg committed Oct 8, 2013
1 parent ddff8e6 commit cc5962b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion brian2/groups/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __getattr__(self, name):
def __setattr__(self, name, val):
# attribute access is switched off until this attribute is created by
# _enable_group_attributes
if not hasattr(self, '_group_attribute_access_active'):
if not hasattr(self, '_group_attribute_access_active') or name in self.__dict__:
object.__setattr__(self, name, val)
elif name in self.variables:
var = self.variables[name]
Expand Down
15 changes: 11 additions & 4 deletions brian2/synapses/synapses.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import weakref
import itertools
import re
import bisect

import numpy as np

Expand Down Expand Up @@ -210,14 +211,20 @@ def before_run(self, namespace):
)
self.updaters.insert(0, self.pushspikes_codeobj.get_updater())
#self.updaters.insert(0, SynapticPathwayUpdater(self))

def push_spikes(self):
# Push new spikes into the queue
spikes = self.source.spikes
# Make use of the fact that the spikes list is sorted for faster
# subgroup handling
start = self.spikes_start
start_idx = bisect.bisect_left(spikes, start)
stop_idx = bisect.bisect_left(spikes, self.spikes_stop, lo=start_idx)
spikes = spikes[start_idx:stop_idx]
synapse_indices = self.synapse_indices
if len(spikes):
indices = np.concatenate([self.synapse_indices[spike - self.spikes_start][:]
for spike in spikes
if self.spikes_start <= spike < self.spikes_stop]).astype(np.int32)
indices = np.concatenate([synapse_indices[spike - start][:]
for spike in spikes]).astype(np.int32)

if len(indices):
if len(self._delays) > 1:
Expand Down

0 comments on commit cc5962b

Please sign in to comment.