Skip to main content

DenseLayer

Struct DenseLayer 

Source
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: usize

Number of input features.

§n_neurons: usize

Number of output neurons.

§length: usize

Bitstream length per encoded scalar.

§words_per_input: usize

Words 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: u64

Implementations§

Source§

impl DenseLayer

Source

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).

Source

fn weight_slice(&self, neuron: usize, input: usize) -> &[u64]

Return a single [word] slice for one neuron/input pair.

Source

pub fn get_weights(&self) -> Vec<Vec<f64>>

Return a copy of weight matrix.

Source

pub fn set_weights(&mut self, weights: Vec<Vec<f64>>) -> Result<(), String>

Set probability weights and refresh packed representation.

Source

pub fn refresh_packed_weights(&mut self)

Rebuild packed weight bitstreams from current weight matrix.

Source

pub fn forward( &self, input_values: &[f64], seed: u64, ) -> Result<Vec<f64>, String>

Forward pass using stochastic bitstreams.

Returns one activation value per neuron.

Source

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).

Source

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.

Source

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]
Source

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].

Source

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)
Source

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.

Source

pub fn forward_numpy_inner( &self, input_values: &[f64], seed: u64, ) -> Result<Vec<f64>, String>

Single-call dense forward with parallel Bernoulli encoding.

This mirrors forward_fast and exists for numpy-native Python bindings.

Trait Implementations§

Source§

impl Clone for DenseLayer

Source§

fn clone(&self) -> DenseLayer

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DenseLayer

Source§

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

Formats the value using the given formatter. 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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> Ungil for T
where T: Send,