pub struct SpikeDelayBuffer { /* private fields */ }Expand description
Ring-buffer delay queue for spike delivery.
At each simulation tick:
- Call
SpikeDelayBuffer::injectfor each spiking synapse to schedule future delivery. - Call
SpikeDelayBuffer::drain_current_tickorSpikeDelayBuffer::drain_current_tick_intoto collect all currents that have arrived. - Call
SpikeDelayBuffer::advanceto move the tick forward.
With max_delay == 0 the buffer holds a single slot and every spike is
delivered in the same tick it is injected, behaving as if there were no
delay layer — it still allocates that one slot, one f32 per neuron.
Deserialization re-validates the ring invariants: depth is
max_delay + 1 (checked, nonzero), every slot width equals
neuron_count, every stored current is finite, current_tick + max_delay
fits in usize so inject/drain slot arithmetic cannot overflow, and
current_tick leaves one-tick headroom so advance cannot land on
usize::MAX. Empty-neuron buffers (neuron_count == 0) remain legal
when each slot is an empty vector.
Implementations§
Source§impl SpikeDelayBuffer
impl SpikeDelayBuffer
Sourcepub fn new(neuron_count: usize, max_delay: usize) -> Self
pub fn new(neuron_count: usize, max_delay: usize) -> Self
Create a new delay buffer.
The ring has max_delay + 1 slots so a spike injected with
delay == max_delay lands on a future tick rather than wrapping
onto the current slot.
§Arguments
neuron_count— number of target neurons (slot width)max_delay— maximum axonal delay in ticks
§Panics
Panics if max_delay + 1 overflows usize. Prefer
SpikeDelayBuffer::try_new when the caller needs a recoverable
error.
Sourcepub fn try_new(neuron_count: usize, max_delay: usize) -> Result<Self>
pub fn try_new(neuron_count: usize, max_delay: usize) -> Result<Self>
Fallible constructor that rejects a max_delay whose ring depth
(max_delay + 1) would overflow usize.
Sourcepub fn inject(&mut self, target: usize, weight: f32, delay: usize)
pub fn inject(&mut self, target: usize, weight: f32, delay: usize)
Inject a spike from a source neuron through a synapse.
The synaptic current weight will be delivered to target neuron
after delay ticks from the current tick.
Bounds are checked in both debug and release builds before any slot is modified. An oversized delay is rejected rather than wrapping onto an earlier tick via modulo arithmetic.
§Panics
Panics if delay > max_delay or target >= neuron_count. Prefer
SpikeDelayBuffer::try_inject when the caller needs a recoverable
error.
Sourcepub fn try_inject(
&mut self,
target: usize,
weight: f32,
delay: usize,
) -> Result<()>
pub fn try_inject( &mut self, target: usize, weight: f32, delay: usize, ) -> Result<()>
Fallible inject that leaves the buffer unchanged when delay or
target is out of range.
Sourcepub fn drain_current_tick(&mut self) -> Vec<f32>
pub fn drain_current_tick(&mut self) -> Vec<f32>
Drain the current tick’s accumulated synaptic currents.
Returns a vector of length neuron_count with the total synaptic
current arriving at each neuron in this tick. The slot is zeroed
after draining.
Prefer SpikeDelayBuffer::drain_current_tick_into when the caller
can reuse an output buffer.
Sourcepub fn drain_current_tick_into(&mut self, output: &mut [f32]) -> Result<()>
pub fn drain_current_tick_into(&mut self, output: &mut [f32]) -> Result<()>
Drain the current tick into a caller-owned buffer.
output is overwritten with this tick’s currents and must have
length neuron_count(). On success the drained slot is zeroed. On
a length mismatch the buffer is left unchanged — output is not
written and no slot is cleared.
Sourcepub fn current_tick(&self) -> u64
pub fn current_tick(&self) -> u64
Current simulation tick.
Sourcepub fn neuron_count(&self) -> usize
pub fn neuron_count(&self) -> usize
Number of neurons (slot width).
Trait Implementations§
Source§impl Clone for SpikeDelayBuffer
impl Clone for SpikeDelayBuffer
Source§fn clone(&self) -> SpikeDelayBuffer
fn clone(&self) -> SpikeDelayBuffer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more