diff --git a/brian2/groups/group.py b/brian2/groups/group.py index 859ba7d16..f9dcdb8fa 100644 --- a/brian2/groups/group.py +++ b/brian2/groups/group.py @@ -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] diff --git a/brian2/synapses/synapses.py b/brian2/synapses/synapses.py index 971c43904..8d3f97bce 100644 --- a/brian2/synapses/synapses.py +++ b/brian2/synapses/synapses.py @@ -3,6 +3,7 @@ import weakref import itertools import re +import bisect import numpy as np @@ -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: