| 1 |
{# USES_VARIABLES { N, _clock_t, count, |
| 2 |
_source_start, _source_stop} #} |
| 3 |
{% extends 'common_group.pyx' %} |
| 4 |
|
| 5 |
{% block maincode %} |
| 6 |
|
| 7 |
{# Get the name of the array that stores these events (e.g. the spikespace array) #} |
| 8 |
{% set _eventspace = get_array_name(eventspace_variable) %} |
| 9 |
cdef size_t _num_events = {{_eventspace}}[_num{{_eventspace}}-1] |
| 10 |
cdef size_t _start_idx, _end_idx, _curlen, _newlen, _j |
| 11 |
{% for varname, var in record_variables | dictsort %} |
| 12 |
cdef {{cpp_dtype(var.dtype)}}* _{{varname}}_ptr |
| 13 |
{% endfor %} |
| 14 |
if _num_events > 0: |
| 15 |
# For subgroups, we do not want to record all spikes |
| 16 |
# We assume that spikes are ordered |
| 17 |
_start_idx = _num_events |
| 18 |
_end_idx = _num_events |
| 19 |
for _j in range(_num_events): |
| 20 |
_idx = {{_eventspace}}[_j] |
| 21 |
if _idx >= _source_start: |
| 22 |
_start_idx = _j |
| 23 |
break |
| 24 |
for _j in range(_num_events-1, _start_idx-1, -1): |
| 25 |
_idx = {{_eventspace}}[_j] |
| 26 |
if _idx < _source_stop: |
| 27 |
break |
| 28 |
_end_idx = _j |
| 29 |
_num_events = _end_idx - _start_idx |
| 30 |
if _num_events > 0: |
| 31 |
# scalar code |
| 32 |
_vectorisation_idx = 1 |
| 33 |
{{ scalar_code|autoindent }} |
| 34 |
_curlen = {{N}} |
| 35 |
_newlen = _curlen + _num_events |
| 36 |
# Resize the C++ arrays directly, avoiding Python indirection for efficiency |
| 37 |
{% for varname, var in record_variables | dictsort %} |
| 38 |
{% set dyn_array_name = get_array_name(var, access_data=False) %} |
| 39 |
{{dyn_array_name}}_ptr.resize(_newlen) |
| 40 |
{% endfor %} |
| 41 |
# Update N after resize |
| 42 |
{{N}} = _newlen |
| 43 |
|
| 44 |
# No we get new fresh pointers after resize |
| 45 |
{% for varname, var in record_variables | dictsort %} |
| 46 |
{% set dyn_array_name = get_array_name(var, access_data=False) %} |
| 47 |
_{{varname}}_ptr = {{dyn_array_name}}_ptr.get_data_ptr() |
| 48 |
{% endfor %} |
| 49 |
|
| 50 |
# Copy the values across |
| 51 |
for _j in range(_start_idx, _end_idx): |
| 52 |
_idx = {{_eventspace}}[_j] |
| 53 |
_vectorisation_idx = _idx |
| 54 |
{{ vector_code|autoindent }} |
| 55 |
{% for varname in record_variables | sort %} |
| 56 |
_{{varname}}_ptr[_curlen + _j - _start_idx] = _to_record_{{varname}} |
| 57 |
{% endfor %} |
| 58 |
{{count}}[_idx - _source_start] += 1 |
| 59 |
{% endblock %} |