pub struct SparseGradient {
pub values: Vec<f32>,
pub indices: Vec<usize>,
pub row_ptr: Vec<usize>,
pub shape: Vec<usize>,
pub total_elements: usize,
pub sparsity_ratio: f32,
}Expand description
Sparse gradient representation using Compressed Sparse Row (CSR) format
Fields§
§values: Vec<f32>Non-zero values
indices: Vec<usize>Column indices of non-zero values
row_ptr: Vec<usize>Row pointers (for 2D gradients)
shape: Vec<usize>Shape of the original dense gradient
total_elements: usizeTotal number of elements
sparsity_ratio: f32Sparsity ratio (0.0 = dense, 1.0 = completely sparse)
Implementations§
Source§impl SparseGradient
impl SparseGradient
Sourcepub fn from_dense(gradient: &[f32], shape: Vec<usize>, threshold: f32) -> Self
pub fn from_dense(gradient: &[f32], shape: Vec<usize>, threshold: f32) -> Self
Create a sparse gradient from a dense gradient
Sourcepub fn is_worth_sparse(&self, min_sparsity_ratio: f32) -> bool
pub fn is_worth_sparse(&self, min_sparsity_ratio: f32) -> bool
Check if this gradient is sparse enough to benefit from sparse representation
Sourcepub fn memory_footprint(&self) -> usize
pub fn memory_footprint(&self) -> usize
Get memory footprint in bytes
Sourcepub fn compression_ratio(&self) -> f32
pub fn compression_ratio(&self) -> f32
Get compression ratio compared to dense representation
Sourcepub fn add(&mut self, other: &SparseGradient) -> Result<(), OptimizerError>
pub fn add(&mut self, other: &SparseGradient) -> Result<(), OptimizerError>
Add another sparse gradient (element-wise addition)
Trait Implementations§
Source§impl Clone for SparseGradient
impl Clone for SparseGradient
Source§fn clone(&self) -> SparseGradient
fn clone(&self) -> SparseGradient
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 SparseGradient
impl RefUnwindSafe for SparseGradient
impl Send for SparseGradient
impl Sync for SparseGradient
impl Unpin for SparseGradient
impl UnsafeUnpin for SparseGradient
impl UnwindSafe for SparseGradient
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