pub struct ConvNetBlock {
pub conv: Conv1dDyn,
pub bn: BatchNorm1D,
pub activation: ActivationType,
pub state: WaveNetLayerState,
/* private fields */
}Expand description
A single ConvNet feed-forward block.
Processing pipeline:
- Write input frames into the causal ring buffer
- Run causal Conv1D on the ring buffer → scratch buffer
- Apply BatchNorm (affine transform) in-place on scratch
- Apply activation function in-place on scratch
- Copy scratch to output
Fields§
§conv: Conv1dDynCausal 1D convolution (runtime dimensions).
bn: BatchNorm1DBatch normalization (pre-fused affine transform).
activation: ActivationTypeActivation function applied after batch norm.
state: WaveNetLayerStateRing buffer state for causal convolution lookback.
Implementations§
Source§impl ConvNetBlock
impl ConvNetBlock
Sourcepub fn new(
in_ch: usize,
out_ch: usize,
kernel: usize,
dilation: usize,
do_bias: bool,
activation: ActivationType,
alloc_num: usize,
) -> Result<Self>
pub fn new( in_ch: usize, out_ch: usize, kernel: usize, dilation: usize, do_bias: bool, activation: ActivationType, alloc_num: usize, ) -> Result<Self>
Creates a new ConvNetBlock with zero-initialized weights.
Weights must be populated via set_conv_weights / set_conv_bias
and set_bn_params by the dispatcher.
Sourcepub fn receptive_field(&self) -> usize
pub fn receptive_field(&self) -> usize
Returns the receptive field contribution of this block.
Sourcepub fn set_conv_weights(&mut self, weights: &[f32])
pub fn set_conv_weights(&mut self, weights: &[f32])
Loads convolution weights from a flat f32 slice.
Sourcepub fn set_conv_bias(&mut self, bias: &[f32])
pub fn set_conv_bias(&mut self, bias: &[f32])
Loads convolution bias from a flat f32 slice.
Sourcepub fn set_bn_params(
&mut self,
scale: &[f32],
offset: &[f32],
) -> Result<(), NamErrorCode>
pub fn set_bn_params( &mut self, scale: &[f32], offset: &[f32], ) -> Result<(), NamErrorCode>
Loads pre-fused batch norm parameters.
Sourcepub unsafe fn process_block(
&mut self,
input: &[f32],
output: &mut [f32],
num_frames: usize,
)
pub unsafe fn process_block( &mut self, input: &[f32], output: &mut [f32], num_frames: usize, )
Public dispatch wrapper that selects the optimal SIMD path.
§Safety
Input and output slices must have sizes compatible with the block dimensions:
input.len() == num_frames * in_ch, output.len() == num_frames * out_ch.
Sourcepub unsafe fn process_block_internal<M: SimdMath>(
&mut self,
input: &[f32],
output: &mut [f32],
num_frames: usize,
)
pub unsafe fn process_block_internal<M: SimdMath>( &mut self, input: &[f32], output: &mut [f32], num_frames: usize, )
SIMD-dispatched processing kernel.
§Safety
input.len() must equal num_frames * in_ch.
output.len() must equal num_frames * out_ch.
Sourcepub unsafe fn prewarm_internal<M: SimdMath>(&mut self)
pub unsafe fn prewarm_internal<M: SimdMath>(&mut self)
Fills the conv state buffer with a single frame of silence replicated backward to cover the entire receptive field.
§Safety
Must be called via dispatch_simd! macro. The state buffer must be
properly allocated and the ring buffer start pointer must be valid.
Trait Implementations§
Source§impl Clone for ConvNetBlock
impl Clone for ConvNetBlock
Source§fn clone(&self) -> ConvNetBlock
fn clone(&self) -> ConvNetBlock
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ConvNetBlock
impl RefUnwindSafe for ConvNetBlock
impl Send for ConvNetBlock
impl Sync for ConvNetBlock
impl Unpin for ConvNetBlock
impl UnsafeUnpin for ConvNetBlock
impl UnwindSafe for ConvNetBlock
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.