pub struct LinearSegment {
pub weights: Vec<f32>,
pub in_dim: usize,
pub out_dim: usize,
}Expand description
A simple fully-connected (linear/dense) layer operating on flat f32
vectors.
Implements the linear transformation y = W x (no bias) where W is a
[out_dim × in_dim] matrix stored in row-major order.
This is primarily intended for testing gradient-checkpointing mechanics without pulling in heavy tensor libraries.
Fields§
§weights: Vec<f32>Weight matrix stored row-major: weights[i * in_dim + j] = W[i, j].
in_dim: usizeNumber of input features.
out_dim: usizeNumber of output features.
Implementations§
Source§impl LinearSegment
impl LinearSegment
Sourcepub fn new(weights: Vec<f32>, in_dim: usize, out_dim: usize) -> Self
pub fn new(weights: Vec<f32>, in_dim: usize, out_dim: usize) -> Self
Create a LinearSegment from explicit weights.
§Panics (debug only)
Panics if weights.len() != in_dim * out_dim.
Sourcepub fn random_init(in_dim: usize, out_dim: usize, seed: u64) -> Self
pub fn random_init(in_dim: usize, out_dim: usize, seed: u64) -> Self
Initialise weights pseudo-randomly using a simple 64-bit LCG.
The LCG parameters (multiplier / increment) are the same as used by
Knuth and Numerical Recipes. Weights are scaled to [-1, 1] using
Xavier-style normalisation: w ∈ [-sqrt(6/(in+out)), sqrt(6/(in+out))].
No external rand crate is required.
Trait Implementations§
Source§impl Clone for LinearSegment
impl Clone for LinearSegment
Source§fn clone(&self) -> LinearSegment
fn clone(&self) -> LinearSegment
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 LinearSegment
impl RefUnwindSafe for LinearSegment
impl Send for LinearSegment
impl Sync for LinearSegment
impl Unpin for LinearSegment
impl UnsafeUnpin for LinearSegment
impl UnwindSafe for LinearSegment
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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