pub struct SparseLinear { /* private fields */ }
Expand description
Sparse linear layer (also known as sparse fully connected layer)
Implementations§
Source§impl SparseLinear
impl SparseLinear
Sourcepub fn new(
in_features: usize,
out_features: usize,
sparsity: f32,
use_bias: bool,
) -> TorshResult<Self>
pub fn new( in_features: usize, out_features: usize, sparsity: f32, use_bias: bool, ) -> TorshResult<Self>
Create a new sparse linear layer
Sourcepub fn from_weight(weight: CsrTensor, bias: Option<Tensor>) -> TorshResult<Self>
pub fn from_weight(weight: CsrTensor, bias: Option<Tensor>) -> TorshResult<Self>
Create from existing sparse weight matrix
Sourcepub fn forward(&self, input: &Tensor) -> TorshResult<Tensor>
pub fn forward(&self, input: &Tensor) -> TorshResult<Tensor>
Forward pass
Sourcepub fn num_parameters(&self) -> usize
pub fn num_parameters(&self) -> usize
Get number of parameters (including bias)
Sourcepub fn structured_prune(
&mut self,
ratio: f32,
dimension: usize,
) -> TorshResult<()>
pub fn structured_prune( &mut self, ratio: f32, dimension: usize, ) -> TorshResult<()>
Apply structured pruning (remove entire rows/columns)
Sourcepub fn magnitude_prune(&mut self, ratio: f32) -> TorshResult<()>
pub fn magnitude_prune(&mut self, ratio: f32) -> TorshResult<()>
Apply magnitude-based unstructured pruning
Trait Implementations§
Source§impl Clone for SparseLinear
impl Clone for SparseLinear
Source§fn clone(&self) -> SparseLinear
fn clone(&self) -> SparseLinear
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 moreAuto Trait Implementations§
impl Freeze for SparseLinear
impl RefUnwindSafe for SparseLinear
impl Send for SparseLinear
impl Sync for SparseLinear
impl Unpin for SparseLinear
impl UnwindSafe for SparseLinear
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