Skip to main content

SpikeDelayBuffer

Struct SpikeDelayBuffer 

Source
pub struct SpikeDelayBuffer { /* private fields */ }
Expand description

Ring-buffer delay queue for spike delivery.

At each simulation tick:

  1. Call SpikeDelayBuffer::inject for each spiking synapse to schedule future delivery.
  2. Call SpikeDelayBuffer::drain_current_tick or SpikeDelayBuffer::drain_current_tick_into to collect all currents that have arrived.
  3. Call SpikeDelayBuffer::advance to 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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn advance(&mut self)

Advance to the next tick.

Source

pub fn current_tick(&self) -> u64

Current simulation tick.

Source

pub fn max_delay(&self) -> usize

Maximum delay supported by this buffer.

Source

pub fn neuron_count(&self) -> usize

Number of neurons (slot width).

Source

pub fn reset(&mut self)

Reset all slots and the tick counter.

Trait Implementations§

Source§

impl Clone for SpikeDelayBuffer

Source§

fn clone(&self) -> SpikeDelayBuffer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SpikeDelayBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SpikeDelayBuffer

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for SpikeDelayBuffer

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.