pub struct SparseTensor<const N: usize> {
pub shape: [usize; N],
pub entries: Vec<SparseTensorEntry<N>>,
}Expand description
Sparse N-dimensional tensor in coordinate (COO) format.
The tensor stores only its non-zero entries together with their
multi-indices. Entries with the same index can be present multiple times;
call SparseTensor::canonicalize to merge them.
§Type parameters
N– Tensor order (number of dimensions), fixed at compile time.
Fields§
§shape: [usize; N]Shape of the tensor (length-N array of dimension sizes).
entries: Vec<SparseTensorEntry<N>>Non-zero entries.
Implementations§
Source§impl<const N: usize> SparseTensor<N>
impl<const N: usize> SparseTensor<N>
Sourcepub fn push(&mut self, indices: [usize; N], value: f64)
pub fn push(&mut self, indices: [usize; N], value: f64)
Add an entry to the tensor (does not check for duplicates).
Sourcepub fn nnz_ratio(&self) -> f64
pub fn nnz_ratio(&self) -> f64
Fraction of non-zero elements: nnz / total_elements.
Returns 0.0 if the tensor has zero total elements.
Sourcepub fn canonicalize(&mut self)
pub fn canonicalize(&mut self)
Sort entries lexicographically by index and merge duplicates by summing their values.
After calling this function, entries are in sorted order with no duplicate indices.
Trait Implementations§
Source§impl<const N: usize> Clone for SparseTensor<N>
impl<const N: usize> Clone for SparseTensor<N>
Source§fn clone(&self) -> SparseTensor<N>
fn clone(&self) -> SparseTensor<N>
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<const N: usize> Freeze for SparseTensor<N>
impl<const N: usize> RefUnwindSafe for SparseTensor<N>
impl<const N: usize> Send for SparseTensor<N>
impl<const N: usize> Sync for SparseTensor<N>
impl<const N: usize> Unpin for SparseTensor<N>
impl<const N: usize> UnsafeUnpin for SparseTensor<N>
impl<const N: usize> UnwindSafe for SparseTensor<N>
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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