From 35867edbfc6a3bf219c9391f1014612c6b7b7025 Mon Sep 17 00:00:00 2001 From: thesamovar Date: Tue, 20 Aug 2013 22:09:15 -0400 Subject: [PATCH] Fixed SpikeMonitor to use _spikespace --- .../runtime/numpy_rt/templates/spikemonitor.py_ | 4 ++-- .../runtime/weave_rt/templates/spikemonitor.cpp | 10 +++++----- brian2/monitors/spikemonitor.py | 3 +-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/brian2/codegen/runtime/numpy_rt/templates/spikemonitor.py_ b/brian2/codegen/runtime/numpy_rt/templates/spikemonitor.py_ index 4ba82b17c..b9144cae0 100644 --- a/brian2/codegen/runtime/numpy_rt/templates/spikemonitor.py_ +++ b/brian2/codegen/runtime/numpy_rt/templates/spikemonitor.py_ @@ -1,7 +1,7 @@ -# { USES_VARIABLES _i, _t, _spikes, _count, t, _source_start, _source_end} +# { USES_VARIABLES _i, _t, _spikespace, _count, t, _source_start, _source_end} import numpy as np +_spikes = _spikespace[:_spikespace[-1]] # Take subgroups into account -_spikes = np.asarray(_spikes) _spikes = _spikes[(_spikes >= _source_start) & (_spikes < _source_end)] _spikes -= _source_start _n_spikes = len(_spikes) diff --git a/brian2/codegen/runtime/weave_rt/templates/spikemonitor.cpp b/brian2/codegen/runtime/weave_rt/templates/spikemonitor.cpp index 9d8fac46d..752d7855d 100644 --- a/brian2/codegen/runtime/weave_rt/templates/spikemonitor.cpp +++ b/brian2/codegen/runtime/weave_rt/templates/spikemonitor.cpp @@ -1,8 +1,8 @@ {% macro main() %} - // USES_VARIABLES { _t, _i, t, _spikes, _count, + // USES_VARIABLES { _t, _i, t, _spikespace, _count, // _source_start, _source_end} - + int _num_spikes = _spikespace[_num_spikespace-1]; if (_num_spikes > 0) { // For subgroups, we do not want to record all spikes @@ -12,7 +12,7 @@ int _end_idx = - 1; for(int _i=0; _i<_num_spikes; _i++) { - const int _idx = _spikes[_i]; + const int _idx = _spikespace[_i]; if (_idx >= _source_start) { _start_idx = _i; break; @@ -20,7 +20,7 @@ } for(int _i=_start_idx; _i<_num_spikes; _i++) { - const int _idx = _spikes[_i]; + const int _idx = _spikespace[_i]; if (_idx >= _source_end) { _end_idx = _i; break; @@ -45,7 +45,7 @@ // Copy the values across for(int _i=_start_idx; _i<_end_idx; _i++) { - const int _idx = _spikes[_i]; + const int _idx = _spikespace[_i]; _t_data[_curlen + _i - _start_idx] = t; _i_data[_curlen + _i - _start_idx] = _idx - _source_start; _count[_idx - _source_start]++; diff --git a/brian2/monitors/spikemonitor.py b/brian2/monitors/spikemonitor.py index b2f9dd081..90660dce4 100644 --- a/brian2/monitors/spikemonitor.py +++ b/brian2/monitors/spikemonitor.py @@ -58,8 +58,7 @@ def __init__(self, source, record=True, when=None, name='spikemonitor*', end = getattr(self.source, 'end', len(self.source)) self.variables = {'t': AttributeVariable(second, self.clock, 't'), - '_spikes': AttributeVariable(Unit(1), self.source, - 'spikes'), + '_spikespace': self.source.variables['_spikespace'], # The template needs to have access to the # DynamicArray here, having access to the underlying # array is not enough since we want to do the resize