pub struct SparseTensor<T> {
pub indices: Vec<Vec<usize>>,
pub values: Vec<T>,
pub shape: Vec<usize>,
}Expand description
Sparse tensor in COO (coordinate) format
Fields§
§indices: Vec<Vec<usize>>Indices for each non-zero element (one vector per dimension)
values: Vec<T>Values of non-zero elements
shape: Vec<usize>Shape of the tensor
Implementations§
Source§impl<T> SparseTensor<T>
impl<T> SparseTensor<T>
Sourcepub fn new(
indices: Vec<Vec<usize>>,
values: Vec<T>,
shape: Vec<usize>,
) -> SparseResult<Self>
pub fn new( indices: Vec<Vec<usize>>, values: Vec<T>, shape: Vec<usize>, ) -> SparseResult<Self>
Create a new sparse tensor
Sourcepub fn unfold(&self, mode: usize) -> SparseResult<CsrArray<T>>
pub fn unfold(&self, mode: usize) -> SparseResult<CsrArray<T>>
Mode-n unfolding (matricization)
Unfolds the tensor along the specified mode into a matrix.
Sourcepub fn fold(
matrix: &dyn SparseArray<T>,
shape: Vec<usize>,
mode: usize,
) -> SparseResult<Self>
pub fn fold( matrix: &dyn SparseArray<T>, shape: Vec<usize>, mode: usize, ) -> SparseResult<Self>
Fold a matrix back into a tensor along the specified mode
Sourcepub fn mode_product(
&self,
matrix: &CsrArray<T>,
mode: usize,
) -> SparseResult<Self>
pub fn mode_product( &self, matrix: &CsrArray<T>, mode: usize, ) -> SparseResult<Self>
Tensor-matrix product along specified mode
Multiplies the tensor by a matrix along the given mode.
Sourcepub fn inner_product(&self, other: &Self) -> SparseResult<T>
pub fn inner_product(&self, other: &Self) -> SparseResult<T>
Inner product of two sparse tensors
Sourcepub fn frobenius_norm(&self) -> T
pub fn frobenius_norm(&self) -> T
Frobenius norm of the tensor
Trait Implementations§
Source§impl<T: Clone> Clone for SparseTensor<T>
impl<T: Clone> Clone for SparseTensor<T>
Source§fn clone(&self) -> SparseTensor<T>
fn clone(&self) -> SparseTensor<T>
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<T> Freeze for SparseTensor<T>
impl<T> RefUnwindSafe for SparseTensor<T>where
T: RefUnwindSafe,
impl<T> Send for SparseTensor<T>where
T: Send,
impl<T> Sync for SparseTensor<T>where
T: Sync,
impl<T> Unpin for SparseTensor<T>where
T: Unpin,
impl<T> UnsafeUnpin for SparseTensor<T>
impl<T> UnwindSafe for SparseTensor<T>where
T: UnwindSafe,
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