pub trait Encoder {
// Required methods
fn encode(&mut self, input: &[f32]) -> EncodedOutput;
fn reset(&mut self);
// Provided method
fn encode_step(&mut self, input: &[f32]) -> EncodedOutput { ... }
}Expand description
The core trait for all encoders in this crate.
Encoders convert continuous analog values into discrete spike events for spiking neural networks (SNNs). Two modes are supported:
- Batch mode (
encode): Process a complete input vector at once. - Streaming mode (
encode_step): Process incrementally, one step at a time.
§Example
use axon_encoder::prelude::*;
let mut encoder = RateEncoder::try_new(5.0, 50.0, (0.0, 1.0), 0.010)?;
let input = [0.25, 0.75, 0.5];
// Batch encoding
let output = encoder.encode(&input);
// Reset for streaming (if using stateful encoder)
encoder.reset();Required Methods§
Sourcefn encode(&mut self, input: &[f32]) -> EncodedOutput
fn encode(&mut self, input: &[f32]) -> EncodedOutput
Encodes a slice of analog values into spike events (batch mode).
Provided Methods§
Sourcefn encode_step(&mut self, input: &[f32]) -> EncodedOutput
fn encode_step(&mut self, input: &[f32]) -> EncodedOutput
Encodes a single step incrementally (streaming mode).
By default, this delegates to encode() for stateless encoders.
Stateful encoders should override this to maintain state between calls.
§Arguments
input- A slice of analog values to encode
§Returns
An EncodedOutput containing any spike events generated in this step
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".