pub struct SparseConv1d { /* private fields */ }Expand description
Sparse 1D Convolution layer
Implements 1D convolution operations optimized for sparse inputs and/or sparse kernels. This is particularly useful for time series data, audio processing, and NLP applications where sparsity can naturally occur or be induced through pruning.
Implementations§
Source§impl SparseConv1d
impl SparseConv1d
Sourcepub fn new(
in_channels: usize,
out_channels: usize,
kernel_size: usize,
stride: Option<usize>,
padding: Option<usize>,
dilation: Option<usize>,
sparsity: f32,
use_bias: bool,
) -> TorshResult<Self>
pub fn new( in_channels: usize, out_channels: usize, kernel_size: usize, stride: Option<usize>, padding: Option<usize>, dilation: Option<usize>, sparsity: f32, use_bias: bool, ) -> TorshResult<Self>
Create a new sparse 1D convolution layer
§Arguments
in_channels- Number of input channelsout_channels- Number of output channelskernel_size- Convolution kernel sizestride- Stride for convolution (default: 1)padding- Padding for convolution (default: 0)dilation- Dilation for convolution (default: 1)sparsity- Kernel sparsity level (0.0 = dense, 1.0 = fully sparse)use_bias- Whether to include learnable bias
§Returns
TorshResult<Self>- New sparse 1D convolution layer or error
§Example
use torsh_sparse::nn::convolution::SparseConv1d;
// Create sparse 1D conv: 16->32 channels, kernel size 3, 80% sparse
let conv = SparseConv1d::new(16, 32, 3, None, None, None, 0.8, true).expect("valid conv1d config");Sourcepub fn forward(&self, input: &Tensor) -> TorshResult<Tensor>
pub fn forward(&self, input: &Tensor) -> TorshResult<Tensor>
Sourcepub fn num_parameters(&self) -> usize
pub fn num_parameters(&self) -> usize
Get the number of parameters
Sourcepub fn kernel_sparsity(&self) -> f32
pub fn kernel_sparsity(&self) -> f32
Get kernel sparsity
Sourcepub fn in_channels(&self) -> usize
pub fn in_channels(&self) -> usize
Get input channels
Sourcepub fn out_channels(&self) -> usize
pub fn out_channels(&self) -> usize
Get output channels
Sourcepub fn kernel_size(&self) -> usize
pub fn kernel_size(&self) -> usize
Get kernel size
Trait Implementations§
Source§impl Clone for SparseConv1d
impl Clone for SparseConv1d
Auto Trait Implementations§
impl !Freeze for SparseConv1d
impl RefUnwindSafe for SparseConv1d
impl Send for SparseConv1d
impl Sync for SparseConv1d
impl Unpin for SparseConv1d
impl UnsafeUnpin for SparseConv1d
impl UnwindSafe for SparseConv1d
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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