pub struct Linear<T: Num> { /* private fields */ }
Expand description

A linear layer in a neural network.

Implementations§

source§

impl<T: Num> Linear<T>

source

pub fn new(in_dim: usize, out_dim: usize) -> Self

Creates a new linear layer with the specified input and output dimensions.

§Arguments
  • in_dim - The input dimension of the layer.
  • out_dim - The output dimension of the layer.
§Returns

A new Linear instance.

Trait Implementations§

source§

impl<T: Num> Layer<T> for Linear<T>

source§

fn init_parameters(&mut self, seed: Option<u64>)

Initializes the layer parameters (weight and bias) randomly or with a specified seed.

§Arguments
  • seed - An optional seed value for reproducible parameter initialization.
source§

fn parameters(&self) -> Vec<Variable<T>>

Returns a vector of the layer parameters as Variables.

§Returns

A vector containing the weight and bias variables of the layer.

source§

fn load_parameters(&mut self, parameters: &[Variable<T>])

Loads pre-trained parameters into the layer.

§Arguments
  • parameters - A slice of Variables containing the weight and bias parameters.
§Panics

Panics if the number of parameters is not 2, or if the shapes of the parameters are invalid.

source§

fn call(&self, input: Variable<T>) -> Variable<T>

Performs a forward pass through the layer, applying the linear transformation to the input.

§Arguments
  • input - The input data as a Variable.
§Returns

The output of the layer as a new Variable.

§Panics

Panics if the weight or bias parameters are not initialized.

source§

fn shape_check(&self, input: &Variable<T>)

Checks the shape of the input data to ensure compatibility with the layer.

§Arguments
  • input - The input data as a reference to a Variable.
§Panics

Panics if the input shape is not 2D or if the input dimension does not match the layer’s input dimension.

source§

fn clear_gradients(&self)

Auto Trait Implementations§

§

impl<T> Freeze for Linear<T>

§

impl<T> !RefUnwindSafe for Linear<T>

§

impl<T> !Send for Linear<T>

§

impl<T> !Sync for Linear<T>

§

impl<T> Unpin for Linear<T>

§

impl<T> !UnwindSafe for Linear<T>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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

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

source§

fn vzip(self) -> V