pub struct CsfTensor<T> {
pub shape: Vec<usize>,
pub mode_order: Vec<usize>,
pub fib_ptr: Vec<Vec<usize>>,
pub fib_idx: Vec<Vec<usize>>,
pub values: Vec<T>,
}Expand description
Compressed Sparse Fiber (CSF) tensor.
Stores a sparse tensor of arbitrary order using hierarchical compressed
fiber arrays. Modes are ordered as given by mode_order.
Fields§
§shape: Vec<usize>Shape of the tensor (one entry per mode).
mode_order: Vec<usize>Mode ordering: mode_order[level] = which original mode is at this CSF level.
fib_ptr: Vec<Vec<usize>>Fiber pointers for each non-leaf level.
fib_ptr[l] has length = fib_idx[l].len() + 1.
Children of fiber i at level l are fib_idx[l+1][fib_ptr[l][i]..fib_ptr[l][i+1]].
fib_idx: Vec<Vec<usize>>Fiber indices for each level.
fib_idx[l] stores the coordinate values at CSF level l.
values: Vec<T>Values at the leaf level. values[i] corresponds to fib_idx[ndim-1][i].
Implementations§
Source§impl<T> CsfTensor<T>
impl<T> CsfTensor<T>
Sourcepub fn from_coo(
indices: &[Vec<usize>],
values: &[T],
shape: &[usize],
mode_order: Option<&[usize]>,
) -> SparseResult<Self>
pub fn from_coo( indices: &[Vec<usize>], values: &[T], shape: &[usize], mode_order: Option<&[usize]>, ) -> SparseResult<Self>
Construct a CSF tensor from COO-style data (coordinate lists + values).
§Arguments
indices- A slice of index arrays, one per mode.indices[m][i]is the mode-m coordinate of the i-th non-zero.values- Non-zero values. Length must matchindices[0].len().shape- Shape of the tensor.mode_order- Permutation of0..ndimspecifying which tensor mode goes at each CSF level. PassNonefor natural order.
Sourcepub fn get(&self, indices: &[usize]) -> Option<T>
pub fn get(&self, indices: &[usize]) -> Option<T>
Look up a value by original tensor coordinates.
Returns T::sparse_zero() if the entry is not stored.
Sourcepub fn fiber(
&self,
free_mode: usize,
fixed_indices: &[usize],
) -> SparseResult<Vec<(usize, T)>>
pub fn fiber( &self, free_mode: usize, fixed_indices: &[usize], ) -> SparseResult<Vec<(usize, T)>>
Extract a fiber from the tensor.
A fiber is a 1D slice obtained by fixing all indices except one mode.
Returns (index, value) pairs for the free mode.
§Arguments
free_mode- The mode to leave free (tensor mode index, not CSF level).fixed_indices- Values for all other modes. Length =ndim - 1. The order corresponds to modes0, 1, ..., free_mode-1, free_mode+1, ..., ndim-1.
Sourcepub fn matricize(
&self,
mode: usize,
) -> SparseResult<(Vec<usize>, Vec<usize>, Vec<T>)>
pub fn matricize( &self, mode: usize, ) -> SparseResult<(Vec<usize>, Vec<usize>, Vec<T>)>
Mode-n matricization: unfold the tensor along mode n.
Returns a matrix (in COO form as (rows, cols, vals)) where:
- rows correspond to the free mode’s indices
- columns correspond to the lexicographic combination of all other mode indices
The column index for a multi-index (i_0, ..., i_{n-1}, i_{n+1}, ..., i_{N-1})
is computed as a mixed-radix number.
Sourcepub fn memory_usage(&self) -> usize
pub fn memory_usage(&self) -> usize
Memory usage estimate in bytes.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for CsfTensor<T>
impl<T> RefUnwindSafe for CsfTensor<T>where
T: RefUnwindSafe,
impl<T> Send for CsfTensor<T>where
T: Send,
impl<T> Sync for CsfTensor<T>where
T: Sync,
impl<T> Unpin for CsfTensor<T>where
T: Unpin,
impl<T> UnsafeUnpin for CsfTensor<T>
impl<T> UnwindSafe for CsfTensor<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
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>
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>
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