Debian Codegraph @

brian2/devices/cpp_standalone/templates/synapses_create_array.cpp

raw
1 {# USES_VARIABLES { _synaptic_pre, _synaptic_post, sources, targets,
2 N_incoming, N_outgoing, N,
3 N_pre, N_post, _source_offset, _target_offset }
4 #}
5 {# WRITES_TO_READ_ONLY_VARIABLES { _synaptic_pre, _synaptic_post,
6 N_incoming, N_outgoing, N}
7 #}
8 {% extends 'common_group.cpp' %}
9
10 {% block maincode %}
11
12 const size_t _old_num_synapses = {{N}};
13 const size_t _new_num_synapses = _old_num_synapses + _numsources;
14
15 {# Get N_post and N_pre in the correct way, regardless of whether they are
16 constants or scalar arrays#}
17 const size_t _N_pre = {{constant_or_scalar('N_pre', variables['N_pre'])}};
18 const size_t _N_post = {{constant_or_scalar('N_post', variables['N_post'])}};
19 {{_dynamic_N_incoming}}.resize(_N_post + _target_offset);
20 {{_dynamic_N_outgoing}}.resize(_N_pre + _source_offset);
21
22 for (size_t _idx=0; _idx<_numsources; _idx++) {
23 {# After this code has been executed, the arrays _real_sources and
24 _real_variables contain the final indices. Having any code here it all is
25 only necessary for supporting subgroups #}
26 {{vector_code|autoindent}}
27
28 {{_dynamic__synaptic_pre}}.push_back(_real_sources);
29 {{_dynamic__synaptic_post}}.push_back(_real_targets);
30 // Update the number of total outgoing/incoming synapses per source/target neuron
31 {{_dynamic_N_outgoing}}[_real_sources]++;
32 {{_dynamic_N_incoming}}[_real_targets]++;
33 }
34
35 // now we need to resize all registered variables
36 const size_t newsize = {{_dynamic__synaptic_pre}}.size();
37 {% for varname in owner._registered_variables | variables_to_array_names(access_data=False) | sort %}
38 {{varname}}.resize(newsize);
39 {% endfor %}
40 // Also update the total number of synapses
41 {{N}} = newsize;
42
43 {% if multisynaptic_index %}
44 // Update the "synapse number" (number of synapses for the same
45 // source-target pair)
46 std::map<std::pair<int32_t, int32_t>, int32_t> source_target_count;
47 for (size_t _i=0; _i<newsize; _i++)
48 {
49 // Note that source_target_count will create a new entry initialized
50 // with 0 when the key does not exist yet
51 const std::pair<int32_t, int32_t> source_target = std::pair<int32_t, int32_t>({{_dynamic__synaptic_pre}}[_i], {{_dynamic__synaptic_post}}[_i]);
52 {{get_array_name(variables[multisynaptic_index], access_data=False)}}[_i] = source_target_count[source_target];
53 source_target_count[source_target]++;
54 }
55 {% endif %}
56 {% endblock %}