| 1 |
{# USES_VARIABLES { N, t, rate, _clock_t, _clock_dt, _spikespace, |
| 2 |
_num_source_neurons, _source_start, _source_stop } #} |
| 3 |
{% extends 'common_group.pyx' %} |
| 4 |
|
| 5 |
{% block maincode %} |
| 6 |
|
| 7 |
cdef size_t _num_spikes = {{_spikespace}}[_num{{_spikespace}}-1] |
| 8 |
|
| 9 |
# For subgroups, we do not want to record all spikes |
| 10 |
# We assume that spikes are ordered |
| 11 |
cdef int _start_idx = -1 |
| 12 |
cdef int _end_idx = -1 |
| 13 |
cdef size_t _j |
| 14 |
for _j in range(_num_spikes): |
| 15 |
_idx = {{_spikespace}}[_j] |
| 16 |
if _idx >= _source_start: |
| 17 |
_start_idx = _j |
| 18 |
break |
| 19 |
if _start_idx == -1: |
| 20 |
_start_idx = _num_spikes |
| 21 |
for _j in range(_start_idx, _num_spikes): |
| 22 |
_idx = {{_spikespace}}[_j] |
| 23 |
if _idx >= _source_stop: |
| 24 |
_end_idx = _j |
| 25 |
break |
| 26 |
if _end_idx == -1: |
| 27 |
_end_idx =_num_spikes |
| 28 |
_num_spikes = _end_idx - _start_idx |
| 29 |
|
| 30 |
# First we get the current size of array from the C++ Object itself |
| 31 |
{% set t_array = get_array_name(variables['t'],access_data=False) %} |
| 32 |
{% set rate_array = get_array_name(variables['rate'],access_data=False) %} |
| 33 |
cdef size_t _current_len = {{t_array}}_ptr.size() |
| 34 |
cdef size_t _new_len = _current_len + 1 |
| 35 |
|
| 36 |
# Now we resize the arrays directly , avoiding python indirection |
| 37 |
{{t_array}}_ptr.resize(_new_len) |
| 38 |
{{rate_array}}_ptr.resize(_new_len) |
| 39 |
|
| 40 |
# Update N after resizing |
| 41 |
{{N}} = _new_len |
| 42 |
|
| 43 |
cdef double* _t_data = {{t_array}}_ptr.get_data_ptr() |
| 44 |
cdef double* _rate_data = {{rate_array}}_ptr.get_data_ptr() |
| 45 |
|
| 46 |
# At last we set the new values using the new pointers |
| 47 |
_t_data[_new_len-1] = {{_clock_t}} |
| 48 |
_rate_data[_new_len-1] = _num_spikes/{{_clock_dt}}/_num_source_neurons |
| 49 |
|
| 50 |
{% endblock %} |