Skip to main content

CsfLayout

Struct CsfLayout 

Source
#[non_exhaustive]
pub struct CsfLayout { pub nnz: u64, pub mode_order: Vec<u32>, }
Expand description

Descriptor for the CSF (Compressed Sparse Fiber) sparse layout.

CSF is the rank-N generalisation of CSR/CSC, storing a sparse tensor as a tree of rank levels. Each level compresses one mode with a (pos, crd) pair; the values buffer holds non-zero values at the leaves.

CSF is defined only for rank ≥ 3 tensors in this version of the specification. Rank-2 sparse matrices are served by CSR/CSC; see crate::layout::CsrLayout.

buffer_count = 2·rank+1 comes from the layout descriptor alone because mode_order.len() equals the tensor rank — the rank is embedded in the field, not repeated separately.

§Buffer table

Buffer indexNameElement typeLength
0valuestensor element typennz elements
2L + 1pos_Luint64n_{L-1} + 1 elements (2 for L=0)
2L + 2crd_Luint64n_L elements (nnz for the leaf level)

where n_L is the count of tree nodes at level L, n_{-1} = 1 (virtual root), and n_{rank-1} = nnz.

The byte_offset field MUST be 0 for CSF tensors — the first element is reached by descending the tree, not at a fixed offset.

§Examples

use hurray_core::layout::{CsfLayout, LayoutDescriptor};

// Rank-3 sparse tensor with 4 non-zeros, identity mode_order.
let layout = CsfLayout::new(4, vec![0, 1, 2]);
let desc = LayoutDescriptor::Csf(layout);
assert_eq!(desc.tag(), 0x09);
// 2*rank+1 = 2*3+1 = 7 buffers.
assert_eq!(desc.buffer_count().map(|n| n.get()), Some(7));

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§nnz: u64

Number of stored (non-zero) elements. MAY be 0 for an empty sparse tensor.

§mode_order: Vec<u32>

Permutation of 0..rank-1; mode_order[L] is the logical dimension stored at tree level L. The tensor rank equals mode_order.len().

mode_order is stored here (rather than just rank) because buffer_count() and validate_against_shape() both need it, and carrying the full permutation avoids a separate rank field while making the accessor surface explicit.

Implementations§

Source§

impl CsfLayout

Source

pub fn new(nnz: u64, mode_order: Vec<u32>) -> Self

Creates a new CsfLayout with the given number of non-zeros and mode order.

This constructor does not validate that mode_order is a valid permutation of 0..mode_order.len() or that mode_order.len() >= 3; call crate::layout::LayoutDescriptor::validate_against_shape with the tensor shape to perform those checks.

§Examples
use hurray_core::layout::CsfLayout;

// Rank-3 tensor, identity mode order, 10 non-zeros.
let c = CsfLayout::new(10, vec![0, 1, 2]);
assert_eq!(c.nnz, 10);
assert_eq!(c.mode_order, [0, 1, 2]);

// Rank-4 tensor with reordered modes.
let c4 = CsfLayout::new(0, vec![3, 0, 1, 2]);
assert_eq!(c4.mode_order.len(), 4);

Trait Implementations§

Source§

impl Clone for CsfLayout

Source§

fn clone(&self) -> CsfLayout

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for CsfLayout

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for CsfLayout

Source§

impl Hash for CsfLayout

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for CsfLayout

Source§

fn eq(&self, other: &CsfLayout) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for CsfLayout

Auto Trait Implementations§

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> 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.