Skip to content

Commit

Permalink
Merge 907675d into 6ed4d2b
Browse files Browse the repository at this point in the history
  • Loading branch information
thesamovar committed Aug 19, 2013
2 parents 6ed4d2b + 907675d commit 5e90294
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
10 changes: 6 additions & 4 deletions brian2/codegen/runtime/numpy_rt/templates/threshold.py_
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# USES_VARIABLES { not_refractory, lastspike, t }
# USES_VARIABLES { not_refractory, lastspike, t, _spikespace }
# ITERATE_ALL { _idx }

{% for line in code_lines %}
{{line}}
{% endfor %}
_return_values, = _cond.nonzero()
_spikes, = _cond.nonzero()
_spikespace[-1] = len(_spikes)
_spikespace[:len(_spikes)] = _spikes
# Set the neuron to refractory
not_refractory[_return_values] = False
lastspike[_return_values] = t
not_refractory[_spikes] = False
lastspike[_spikes] = t
11 changes: 4 additions & 7 deletions brian2/codegen/runtime/weave_rt/templates/threshold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//// MAIN CODE /////////////////////////////////////////////////////////////

{% macro main() %}
// USES_VARIABLES { not_refractory, lastspike, t }
// USES_VARIABLES { not_refractory, lastspike, t, _spikespace }
////// SUPPORT CODE ///////
{% for line in support_code_lines %}
// {{line}}
Expand All @@ -24,26 +24,23 @@
{% endfor %}

//// MAIN CODE ////////////
int _cpp_numspikes = 0;
npy_int32 *_spikes_space = (npy_int32 *)malloc(sizeof(npy_int32) * _num_idx);
long _cpp_numspikes = 0;
for(int _idx=0; _idx<_num_idx; _idx++)
{
const int _vectorisation_idx = _idx;
{% for line in code_lines %}
{{line}}
{% endfor %}
if(_cond) {
_spikes_space[_cpp_numspikes++] = _idx;
_spikespace[_cpp_numspikes++] = _idx;
// We have to use the pointer names directly here: The condition
// might contain references to not_refractory or lastspike and in
// that case the names will refer to a single entry.
_ptr{{_array_not_refractory}}[_idx] = false;
_ptr{{_array_lastspike}}[_idx] = t;
}
}
npy_intp _dims[] = {_cpp_numspikes};
PyObject *_numpy_spikes_array = PyArray_SimpleNewFromData(1, _dims, NPY_INT32, _spikes_space);
return_val = _numpy_spikes_array;
_spikespace[_num_idx] = _cpp_numspikes;
{% endmacro %}

////////////////////////////////////////////////////////////////////////////
Expand Down
14 changes: 8 additions & 6 deletions brian2/groups/neurongroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ def __init__(self, group):
def update_abstract_code(self):
self.abstract_code = '_cond = ' + self.group.threshold

def post_update(self, return_value):
# Save the spikes in the NeuronGroup so others can use it
self.group.spikes = return_value


class Resetter(GroupCodeRunner):
'''
Expand Down Expand Up @@ -242,8 +238,7 @@ def __init__(self, N, model, method=None,
##### Setup the memory
self.arrays = self._allocate_memory(dtype=dtype)

#: The array of spikes from the most recent threshold operation
self.spikes = array([], dtype=np.int32)
self._spikespace = np.zeros(N+1, dtype=np.int32)

# Setup the namespace
self.namespace = create_namespace(namespace)
Expand Down Expand Up @@ -310,6 +305,12 @@ def __len__(self):
'''
return self.N

@property
def spikes(self):
'''
The spikes returned by the most recent thresholding operation.
'''
return self._spikespace[:self._spikespace[-1]]

def __getitem__(self, item):
if not isinstance(item, slice):
Expand Down Expand Up @@ -386,6 +387,7 @@ def _create_variables(self):
s = Group._create_variables(self)

# Standard variables always present
s.update({'_spikespace': AttributeVariable(Unit(1), self, '_spikespace', constant=False)})
s.update({'_spikes': AttributeVariable(Unit(1), self,
'spikes', constant=False)})

Expand Down

0 comments on commit 5e90294

Please sign in to comment.