Debian Codegraph @

brian2/codegen/runtime/cython_rt/templates/synapses.pyx

raw
1 {# USES_VARIABLES { _queue_capsule } #}
2 {% extends 'common_group.pyx' %}
3
4 {% block template_support_code %}
5 from cpython.pycapsule cimport PyCapsule_GetPointer
6 from libcpp.vector cimport vector
7 from cython.operator cimport dereference
8 # We declare minimal C++ interface here - only methods we actually want to use
9 # This avoids importing the full SpikeQueue wrapper and its dependencies
10 cdef extern from "spikequeue.h":
11 cdef cppclass CSpikeQueue:
12 vector[int32_t]* peek();
13 void advance();
14 {% endblock %}
15
16 {% block maincode %}
17 # Extract the raw C++ object pointer from the Python capsule.
18 cdef object capsule = _queue_capsule
19 cdef CSpikeQueue* cpp_queue = <CSpikeQueue*>PyCapsule_GetPointer(capsule, "CSpikeQueue")
20
21 # Now we call the C++ peek method directly to get the current spike vector.
22 # This returns a pointer to std::vector<int32_t> containing synapse IDs
23 # that are ready for processing in the current time step.
24 cdef vector[int32_t]* spike_vector = cpp_queue.peek()
25 cdef size_t num_spikes = dereference(spike_vector).size()
26
27 # Early exit for empty queue - avoid all processing overhead
28 if num_spikes == 0:
29 cpp_queue.advance()
30 return
31
32 # Access the underlying raw data pointer of the vector
33 cdef int32_t* spike_data = &dereference(spike_vector)[0]
34
35 # scalar code
36 _vectorisation_idx = 1
37 {{ scalar_code | autoindent }}
38
39
40 cdef size_t i = 0
41 cdef int32_t synapse_id
42 while i < num_spikes:
43 synapse_id = spike_data[i]
44
45 _idx = synapse_id
46 _vectorisation_idx = _idx
47
48 {{ vector_code | autoindent }}
49
50 i += 1
51
52 # Move the queue forward to the next time step
53 cpp_queue.advance()
54
55 {% endblock %}