pub struct LinearModel {
pub weights: AlignedVec<f32>,
pub bias: f32,
pub history: MirroredBuffer<f32>,
pub write_pos: usize,
pub receptive_field: usize,
pub prewarm_on_reset: bool,
pub implementation: LinearImplementation,
pub mode: LinearMode,
/* private fields */
}Expand description
Linear Model — lightweight FIR-based neural model.
This is the simplest NAM architecture: a single linear layer (dot product) applied over the recent sample history with an optional scalar bias.
§RT-Safety
- Zero allocation on the hot-path (
process). - Uses
MirroredBufferfor branch-free ring buffer access. - No locks, no
unwrap(), no I/O.
Fields§
§weights: AlignedVec<f32>FIR filter weights stored in reversed order (matching C++ internal
layout). JSON weights are reversed on construction, so that
dot(weights, oldest_to_newest_window) produces the FIR convolution.
64-byte aligned for AVX2/AVX-512 SIMD loads.
bias: f32Scalar bias added after the dot product.
history: MirroredBuffer<f32>Circular buffer of past input samples, backed by mirrored memory mapping for branch-free contiguous access across the wrap boundary.
write_pos: usizeCurrent write position in the history ring buffer (0..receptive_field-1).
receptive_field: usizeNumber of input samples in the receptive field (= weights.len()).
prewarm_on_reset: boolWhether to execute prewarm during reset(). Default: true.
implementation: LinearImplementationConvolution implementation mode as configured in the JSON.
mode: LinearModeRuntime convolution mode — Direct or Fft with partitioned FFT state.
Implementations§
Source§impl LinearModel
impl LinearModel
Source§impl LinearModel
impl LinearModel
Sourcepub fn new(
weights: Vec<f32>,
bias: f32,
implementation: LinearImplementation,
) -> Result<Self>
pub fn new( weights: Vec<f32>, bias: f32, implementation: LinearImplementation, ) -> Result<Self>
Creates a new LinearModel with the given weights, bias, and implementation.
Weights are expected in forward-time order as stored in the .nam
JSON (w[0] is the response at the current sample). They are reversed
internally to match the C++ nam::Linear layout.
implementation controls the convolution strategy (Auto, Direct, Fft)
as configured in the model’s JSON:
Direct: always uses time-domain dot product.Auto: uses FFT whenreceptive_field >= 256, otherwise Direct.Fft: uses FFT partitioned convolution; falls back to Direct with a warning if the receptive field is too small (< 256).
Allocates the MirroredBuffer for the input history. The buffer is
initialized to zero (silence) by the operating system via mmap.
§Errors
Returns std::io::Error if the MirroredBuffer allocation fails
(e.g., out of memory or virtual address space).
Trait Implementations§
Source§impl NamModel for LinearModel
impl NamModel for LinearModel
Source§fn process(&mut self, input: &[f32], output: &mut [f32])
fn process(&mut self, input: &[f32], output: &mut [f32])
Source§fn prewarm(&mut self, num_samples: usize)
fn prewarm(&mut self, num_samples: usize)
prewarm).Source§fn reset(&mut self, sample_rate: u32, max_buffer_size: usize) -> Result<()>
fn reset(&mut self, sample_rate: u32, max_buffer_size: usize) -> Result<()>
Source§fn prewarm_samples(&self) -> usize
fn prewarm_samples(&self) -> usize
Source§fn prewarm_on_reset(&self) -> bool
fn prewarm_on_reset(&self) -> bool
reset(). Read moreSource§fn set_prewarm_on_reset(&mut self, val: bool)
fn set_prewarm_on_reset(&mut self, val: bool)
reset(). Read moreAuto Trait Implementations§
impl Freeze for LinearModel
impl RefUnwindSafe for LinearModel
impl Send for LinearModel
impl Sync for LinearModel
impl Unpin for LinearModel
impl UnsafeUnpin for LinearModel
impl UnwindSafe for LinearModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.