pub struct LinearLayer { /* private fields */ }Expand description
Dense linear layer: y = x @ weight + bias.
Supports both graph-mode (autograd training) and inference-mode (raw tensors).
Implementations§
Source§impl LinearLayer
impl LinearLayer
Sourcepub fn new(
graph: &mut Graph,
in_features: usize,
out_features: usize,
weight_init: Tensor,
bias_init: Tensor,
) -> Result<Self, ModelError>
pub fn new( graph: &mut Graph, in_features: usize, out_features: usize, weight_init: Tensor, bias_init: Tensor, ) -> Result<Self, ModelError>
Creates a layer from explicit parameter tensors.
Sourcepub fn zero_init(
graph: &mut Graph,
in_features: usize,
out_features: usize,
) -> Result<Self, ModelError>
pub fn zero_init( graph: &mut Graph, in_features: usize, out_features: usize, ) -> Result<Self, ModelError>
Creates a zero-initialized layer.
Sourcepub fn sync_from_graph(&mut self, graph: &Graph) -> Result<(), ModelError>
pub fn sync_from_graph(&mut self, graph: &Graph) -> Result<(), ModelError>
Synchronizes owned tensors from the graph (e.g. after optimizer step).
Sourcepub fn forward(
&self,
graph: &mut Graph,
input: NodeId,
) -> Result<NodeId, ModelError>
pub fn forward( &self, graph: &mut Graph, input: NodeId, ) -> Result<NodeId, ModelError>
Graph-mode forward pass (for training with autograd).
Sourcepub fn forward_inference(&self, input: &Tensor) -> Result<Tensor, ModelError>
pub fn forward_inference(&self, input: &Tensor) -> Result<Tensor, ModelError>
Inference-mode forward pass (no graph needed).
pub fn in_features(&self) -> usize
pub fn out_features(&self) -> usize
pub fn weight_node(&self) -> Option<NodeId>
pub fn bias_node(&self) -> Option<NodeId>
pub fn weight(&self) -> &Tensor
pub fn bias(&self) -> &Tensor
Trait Implementations§
Source§impl Clone for LinearLayer
impl Clone for LinearLayer
Source§fn clone(&self) -> LinearLayer
fn clone(&self) -> LinearLayer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LinearLayer
impl Debug for LinearLayer
Source§impl PartialEq for LinearLayer
impl PartialEq for LinearLayer
impl StructuralPartialEq for LinearLayer
Auto Trait Implementations§
impl Freeze for LinearLayer
impl RefUnwindSafe for LinearLayer
impl Send for LinearLayer
impl Sync for LinearLayer
impl Unpin for LinearLayer
impl UnsafeUnpin for LinearLayer
impl UnwindSafe for LinearLayer
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
Mutably borrows from an owned value. Read more
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>
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 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>
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