Skip to main content

Linear

Struct Linear 

Source
pub struct Linear { /* private fields */ }
Expand description

Contract input, introduce output, and preserve all unrelated axes. Cloning a built Linear explicitly ties its parameters. Carries a learned [output] bias by default; .bias(false) before build omits it entirely, so named_parameters then has only weight and no zero-filled bias tensor is ever allocated.

Implementations§

Source§

impl Linear

Source

pub fn new(input: Axis, output: Dim) -> Self

Source

pub fn bias(self, bias: bool) -> Self

Disable the learned bias term. Has no effect once build has already allocated parameters; call it before build.

Trait Implementations§

Source§

impl Clone for Linear

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Module for Linear

Source§

fn output_shape(&self, input: &Shape) -> Result<Shape>

Source§

fn build(&mut self, input: &Shape, device: &Device, seed: u64) -> Result<Shape>

Infer extents, validate contracts, allocate and initialize parameters; never run forward. Rebuilding with compatible extents/device preserves parameters and ignores the new seed.
Source§

fn forward(&self, input: &Tensor) -> Result<Tensor>

Evaluation semantics: no mode flag on self, no randomness beyond what forward itself already defines. This never changes with the arrival of forward_training.
Source§

fn named_parameters(&self) -> Vec<(String, Parameter)>

Structural paths identify slots; ParamId identifies shared storage within this process.
Source§

fn forward_training( &self, input: &Tensor, pass: &mut TrainingPass, ) -> Result<Tensor>

Training-mode forward pass, driven by an explicit TrainingPass rather than a flag on self. The default implementation ignores pass and calls Module::forward, which is exactly today’s behavior for every module without a train/eval distinction. Override this (never forward, which must stay evaluation semantics) to add explicit randomness or a train/eval difference, such as Dropout. A container that holds child modules (Sequential, or any future one) overrides this to thread the same pass through every child in order, so their draws stay distinct within one step.
Source§

fn parameter(&self, name: &str) -> Result<Parameter>

Source§

fn parameters(&self) -> Vec<Parameter>

Source§

fn zero_grad(&self)

Source§

fn named_states(&self) -> Vec<(String, State)>

Persistent non-parameter tensors this module owns across training steps – BatchNorm-style running statistics. Same slot-path convention as Module::named_parameters: a container (Sequential or any future one) aggregates every child’s own states under "{index}.{name}". Defaults empty, exactly like named_parameters, since most modules have no persistent state. A State here is never written directly; only TrainingPass::commit writes one, after staging in forward_training.
Source§

fn state(&self, name: &str) -> Result<State>

Source§

fn states(&self) -> Vec<State>

Auto Trait Implementations§

§

impl !RefUnwindSafe for Linear

§

impl !Send for Linear

§

impl !Sync for Linear

§

impl !UnwindSafe for Linear

§

impl Freeze for Linear

§

impl Unpin for Linear

§

impl UnsafeUnpin for Linear

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.