pub struct DenseLayer {
pub n_inputs: usize,
pub n_neurons: usize,
pub length: usize,
pub words_per_input: usize,
pub weights: Vec<Vec<f64>>,
packed_weights_flat: Vec<u64>,
weight_seed: u64,
}Expand description
Vectorized stochastic dense layer.
Fields§
§n_inputs: usizeNumber of input features.
n_neurons: usizeNumber of output neurons.
length: usizeBitstream length per encoded scalar.
words_per_input: usizeWords per packed input stream (ceil(length / 64)).
weights: Vec<Vec<f64>>Probability-domain weights in [0, 1].
packed_weights_flat: Vec<u64>Packed bitstream weights in row-major contiguous layout:
[neuron][input][word].
weight_seed: u64Implementations§
Source§impl DenseLayer
impl DenseLayer
Sourcepub fn new(n_inputs: usize, n_neurons: usize, length: usize, seed: u64) -> Self
pub fn new(n_inputs: usize, n_neurons: usize, length: usize, seed: u64) -> Self
Create a layer with random weights sampled from U(0,1).
Sourcefn weight_slice(&self, neuron: usize, input: usize) -> &[u64]
fn weight_slice(&self, neuron: usize, input: usize) -> &[u64]
Return a single [word] slice for one neuron/input pair.
Sourcepub fn get_weights(&self) -> Vec<Vec<f64>>
pub fn get_weights(&self) -> Vec<Vec<f64>>
Return a copy of weight matrix.
Sourcepub fn set_weights(&mut self, weights: Vec<Vec<f64>>) -> Result<(), String>
pub fn set_weights(&mut self, weights: Vec<Vec<f64>>) -> Result<(), String>
Set probability weights and refresh packed representation.
Sourcepub fn refresh_packed_weights(&mut self)
pub fn refresh_packed_weights(&mut self)
Rebuild packed weight bitstreams from current weight matrix.
Sourcepub fn forward(
&self,
input_values: &[f64],
seed: u64,
) -> Result<Vec<f64>, String>
pub fn forward( &self, input_values: &[f64], seed: u64, ) -> Result<Vec<f64>, String>
Forward pass using stochastic bitstreams.
Returns one activation value per neuron.
Sourcepub fn forward_fast(
&self,
input_values: &[f64],
seed: u64,
) -> Result<Vec<f64>, String>
pub fn forward_fast( &self, input_values: &[f64], seed: u64, ) -> Result<Vec<f64>, String>
Forward pass with parallel input encoding.
Each input is encoded with an independently-seeded RNG:
seed + input_index (wrapping).
Sourcepub fn forward_fused(
&self,
input_values: &[f64],
seed: u64,
) -> Result<Vec<f64>, String>
pub fn forward_fused( &self, input_values: &[f64], seed: u64, ) -> Result<Vec<f64>, String>
Forward pass with fused encode+AND+popcount.
This path avoids materializing encoded inputs and consumes each encoded word immediately against its corresponding weight words.
Sourcepub fn forward_batch_into(
&self,
inputs_flat: &[f64],
n_samples: usize,
seed: u64,
output: &mut [f64],
) -> Result<(), String>
pub fn forward_batch_into( &self, inputs_flat: &[f64], n_samples: usize, seed: u64, output: &mut [f64], ) -> Result<(), String>
Batched forward pass writing into an existing row-major output buffer.
inputs_flat: shape[n_samples, n_inputs]output: shape[n_samples, n_neurons]
Sourcepub fn forward_batch(
&self,
inputs_flat: &[f64],
n_samples: usize,
seed: u64,
) -> Result<Vec<f64>, String>
pub fn forward_batch( &self, inputs_flat: &[f64], n_samples: usize, seed: u64, ) -> Result<Vec<f64>, String>
Batched forward pass: process N input vectors in one call.
inputs_flat is row-major: [n_samples, n_inputs].
Returns flat output: [n_samples, n_neurons].
Sourcepub fn forward_prepacked(
&self,
packed_inputs: &[Vec<u64>],
) -> Result<Vec<f64>, String>
pub fn forward_prepacked( &self, packed_inputs: &[Vec<u64>], ) -> Result<Vec<f64>, String>
Forward pass with pre-packed input bitstreams.
packed_inputs must have shape:
- outer length =
n_inputs - inner length =
ceil(length / 64)
Sourcepub fn forward_prepacked_2d(
&self,
packed_flat: &[u64],
n_inputs: usize,
words: usize,
) -> Result<Vec<f64>, String>
pub fn forward_prepacked_2d( &self, packed_flat: &[u64], n_inputs: usize, words: usize, ) -> Result<Vec<f64>, String>
Forward pass with pre-packed inputs from a 2-D contiguous array.
packed_flat is a flat row-major buffer of shape [n_inputs, words].
Each row is one input’s packed bitstream words.
Trait Implementations§
Source§impl Clone for DenseLayer
impl Clone for DenseLayer
Source§fn clone(&self) -> DenseLayer
fn clone(&self) -> DenseLayer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DenseLayer
impl RefUnwindSafe for DenseLayer
impl Send for DenseLayer
impl Sync for DenseLayer
impl Unpin for DenseLayer
impl UnsafeUnpin for DenseLayer
impl UnwindSafe for DenseLayer
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more