Skip to main content

CsfTensor

Struct CsfTensor 

Source
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>
where T: Clone + Copy + Zero + SparseElement + Debug,

Source

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 match indices[0].len().
  • shape - Shape of the tensor.
  • mode_order - Permutation of 0..ndim specifying which tensor mode goes at each CSF level. Pass None for natural order.
Source

pub fn ndim(&self) -> usize

Number of dimensions.

Source

pub fn nnz(&self) -> usize

Number of stored non-zeros.

Source

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.

Source

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 modes 0, 1, ..., free_mode-1, free_mode+1, ..., ndim-1.
Source

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.

Source

pub fn memory_usage(&self) -> usize

Memory usage estimate in bytes.

Trait Implementations§

Source§

impl<T: Clone> Clone for CsfTensor<T>

Source§

fn clone(&self) -> CsfTensor<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for CsfTensor<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V