pub struct SparseMask {
pub mask: Vec<bool>,
}Expand description
Boolean pruning mask over a weight tensor.
true → weight is active (kept).
false → weight is pruned (zeroed).
Fields§
§mask: Vec<bool>Element-wise mask (same length as the weight tensor).
Implementations§
Source§impl SparseMask
impl SparseMask
Sourcepub fn all_active(n: usize) -> Self
pub fn all_active(n: usize) -> Self
Create a mask with all weights active (unpruned).
Sourcepub fn all_pruned(n: usize) -> Self
pub fn all_pruned(n: usize) -> Self
Create a mask with all weights pruned.
Sourcepub fn count_active(&self) -> usize
pub fn count_active(&self) -> usize
Number of active (non-pruned) weights.
Sourcepub fn count_pruned(&self) -> usize
pub fn count_pruned(&self) -> usize
Number of pruned weights.
Sourcepub fn apply(&self, weights: &[f32]) -> Vec<f32>
pub fn apply(&self, weights: &[f32]) -> Vec<f32>
Apply the mask to a weight slice: pruned weights become 0.
Returns a new Vec<f32> of the same length.
§Panics
Panics if weights.len() != self.len().
Sourcepub fn apply_in_place(&self, weights: &mut [f32])
pub fn apply_in_place(&self, weights: &mut [f32])
Trait Implementations§
Source§impl Clone for SparseMask
impl Clone for SparseMask
Source§fn clone(&self) -> SparseMask
fn clone(&self) -> SparseMask
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 SparseMask
impl RefUnwindSafe for SparseMask
impl Send for SparseMask
impl Sync for SparseMask
impl Unpin for SparseMask
impl UnsafeUnpin for SparseMask
impl UnwindSafe for SparseMask
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