pub struct SparseTensor {
pub values: Tensor,
pub indices: Tensor,
pub shape: Vec<usize>,
pub ndim: usize,
pub nnz: usize,
pub is_coalesced: bool,
}Expand description
Sparse tensor representation using COO (coordinate) format
Fields§
§values: TensorTensor values (non-zero elements)
indices: TensorIndices of non-zero elements [2, nnz] for 2D, [3, nnz] for 3D, etc.
shape: Vec<usize>Shape of the full tensor
ndim: usizeNumber of dimensions
nnz: usizeNumber of non-zero elements
is_coalesced: boolWhether the tensor is coalesced (indices are ordered and unique)
Implementations§
Source§impl SparseTensor
impl SparseTensor
Sourcepub fn new(
values: Tensor,
indices: Tensor,
shape: Vec<usize>,
) -> TorshResult<Self>
pub fn new( values: Tensor, indices: Tensor, shape: Vec<usize>, ) -> TorshResult<Self>
Create a new sparse tensor from values and indices
Sourcepub fn from_dense(dense: &Tensor) -> TorshResult<Self>
pub fn from_dense(dense: &Tensor) -> TorshResult<Self>
Create a sparse tensor from dense tensor
Sourcepub fn to_dense(&self) -> TorshResult<Tensor>
pub fn to_dense(&self) -> TorshResult<Tensor>
Convert sparse tensor to dense tensor
Sourcepub fn coalesce(&mut self) -> TorshResult<()>
pub fn coalesce(&mut self) -> TorshResult<()>
Coalesce the sparse tensor (combine duplicate indices)
Sourcepub fn is_coalesced(&self) -> bool
pub fn is_coalesced(&self) -> bool
Check if the tensor is coalesced
Trait Implementations§
Source§impl Clone for SparseTensor
impl Clone for SparseTensor
Source§fn clone(&self) -> SparseTensor
fn clone(&self) -> SparseTensor
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 SparseTensor
impl RefUnwindSafe for SparseTensor
impl Send for SparseTensor
impl Sync for SparseTensor
impl Unpin for SparseTensor
impl UnsafeUnpin for SparseTensor
impl UnwindSafe for SparseTensor
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