Skip to main content

SparseMtxData

Struct SparseMtxData 

Source
pub struct SparseMtxData { /* private fields */ }
Expand description

10x-like cell-feature matrix with zarr backend (feature x cell)

(root)
    ├── nrow
    ├── ncell
    ├── by_column
    │   ├── data
    │   ├── indices (row indices)
    │   └── indptr (column pointers)
    └── by_row
        ├── data
        ├── indices (column indices)
        └── indptr (row pointers)

Implementations§

Source§

impl SparseMtxData

Source

pub fn new(zarr_file: Option<&str>) -> Result<Self>

Create an empty new SparseMtxData instance with a zarr backend file If no backend_file is provided, a temporary file will be created.

  • backend_file - Optional zarr backend file
Source

pub fn open(backend_file: &str) -> Result<Self>

Create SparseMtxData instance from an existing zarr backend file

  • zarr_file - zarr backend file (directory or .zarr.zip)
Source

pub fn from_mtx_file( mtx_file: &str, backend_file: Option<&str>, index_by_row: Option<bool>, ) -> Result<Self>

Create SparseMtxData from mtx file with backend_file as the backend file. If no backend_file is provided, it will be the same as mtx_file with .zarr extension.

  • mtx_file: mtx file to be read into zarr backend
  • backend_file: zarr file to be associated with
  • index_by_row: if true, the matrix will be indexed by row
Source

pub fn from_ndarray( array: &Array2<f32>, zarr_file: Option<&str>, index_by_row: Option<bool>, ) -> Result<Self>

Create a new SparseMtxData instance from an ndarray array

  • array - 2D array to be added to the backend
  • backend_file - Optional zarr backend file
  • index_by_row - Optional flag to index by row (CSR format)
Source

pub fn from_dmatrix( matrix: &DMatrix<f32>, zarr_file: Option<&str>, index_by_row: Option<bool>, ) -> Result<Self>

Create a new SparseMtxData instance from an DMatrix array

  • array - 2D array to be added to the backend
  • backend_file - Optional zarr backend file
  • index_by_row - Optional flag to index by row (CSR format)
Source

pub fn print_hierarchy(&self) -> Result<()>

Show the hierarchy of the zarr store

Trait Implementations§

Source§

impl Clone for SparseMtxData

Source§

fn clone(&self) -> Self

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 SparseIo for SparseMtxData

Source§

fn read_row_indptr(&mut self) -> Result<()>

Read row index pointers

Source§

fn column_indptr(&self) -> &[u64]

Read column index pointers

Source§

fn preload_columns(&mut self) -> Result<()>

preload columns’ values and indices

Source§

fn preload_rows(&mut self) -> Result<()>

preload rows’ values and indices

Source§

fn record_mtx_shape( &mut self, mtx_shape: Option<(usize, usize, usize)>, ) -> Result<()>

Helper function to keep the matrix shape

Source§

fn initialize_backend(&mut self) -> Result<()>

Helper function to create a new zarr backend file

Source§

fn remove_backend_file(&self) -> Result<()>

Clean up the backend file

Source§

fn get_backend_file_name(&self) -> &str

Access file name of the zarr backend

Source§

fn to_mtx_file(&self, mtx_file: &str) -> Result<()>

Export the data to a mtx file. This will take time.

  • mtx_file: mtx file to be written
Source§

fn register_row_names_file(&mut self, row_name_file: &str)

Set row names for the matrix

  • row_name_file: a file each line contains row name words
Source§

fn register_row_names_vec(&mut self, rows: &[Box<str>])

Set row names for the matrix

  • rows: a vector of row names
Source§

fn register_column_names_file(&mut self, column_name_file: &str)

Set column names for the matrix

  • column_name_file: a file each line contains column name words
Source§

fn register_column_names_vec(&mut self, columns: &[Box<str>])

Set column names for the matrix

  • columns: a vector of column names
Source§

fn num_rows(&self) -> Option<usize>

Number of rows in the matrix

Source§

fn num_columns(&self) -> Option<usize>

Number of columns in the matrix

Source§

fn num_non_zeros(&self) -> Option<usize>

Number of non-zero elements in the matrix

Source§

fn register_names_file( &mut self, key: &str, name_file: &str, name_columns: Range<usize>, name_sep: &str, ) -> Result<()>

Add arbitrary names (a vector of strings)

  • group_name: group name
  • name_file: a file each line contains name words
  • name_columns: range of columns to be used for name
  • name_sep: separator for name columns
Source§

fn register_names_vec(&mut self, key: &str, names: &[Box<str>]) -> Result<()>

Add arbitrary names (a vector of strings)

  • group_name: group name
  • names: a file each line contains name words
Source§

fn retrieve_registered_names(&self, key: &str) -> Result<Vec<Box<str>>>

Get back the registered names

  • key: key for the registered names
Source§

fn read_triplets_by_single_column( &self, j_data: usize, ) -> Result<(usize, usize, Vec<(u64, u64, f32)>)>

Read columns within the range and return a vector of triplets (row, col, value)

  • col : usize
Source§

fn read_triplets_by_columns( &self, columns: Self::IndexIter, ) -> Result<(usize, usize, Vec<(u64, u64, f32)>)>

Read columns within the range and return dense ndarray::Array2

  • columns : range e.g., 0..3 -> [0, 1, 2] or vec![0, 1, 2]
Source§

fn read_triplets_by_rows( &self, rows: Self::IndexIter, ) -> Result<(usize, usize, Vec<(u64, u64, f32)>)>

Read rows within the range and return a vector of triplets (row, col, value)

  • rows : range e.g., 0..3 -> [0, 1, 2] or vec![0, 1, 2]
Source§

fn record_csr_dataset_backend( &mut self, csr_cols: &[u64], csr_vals: &[f32], csr_rowptr: &[u64], ) -> Result<()>

CSR data structure in Zarr backend

    └── by_row
        ├── data
        ├── indices (column indices)
        └── isndptr (row pointers)
Source§

fn record_csc_dataset_backend( &mut self, csc_rows: &[u64], csc_vals: &[f32], csc_colptr: &[u64], ) -> Result<()>

CSC data structure in Zarr backend

Helper function to record the CSC dataset
    ├── by_column
    │   ├── data
    │   ├── indices (row indices)
    │   └── indptr (column pointers)
Source§

type IndexIter = Vec<usize>

Source§

fn reopen_backend(&mut self) -> Result<()>

Re-open handles on the CURRENT backend path after its contents were replaced from outside (a finished temp file renamed into place). The zarr store is path-addressed so this is a cache refresh; hdf5 holds an open file handle that would otherwise point at the deleted inode.
Source§

fn read_column_indptr(&mut self) -> Result<()>

preload column index pointers
Source§

fn clean_preloaded_columns(&mut self)

unload the memory
Source§

fn clean_preloaded_rows(&mut self)

unload the row memory
Source§

fn backend_type(&self) -> SparseIoBackend

backend file type
Source§

fn row_names(&self) -> Result<Vec<Box<str>>>

Source§

fn column_names(&self) -> Result<Vec<Box<str>>>

Source§

fn csc_column_arrays(&self) -> Option<(&[u64], &[u64], &[f32])>

Zero-copy view of preloaded column-major CSC arrays as (indptr, indices, data). Returns None when the backend has not preloaded columns or doesn’t support direct array access. Callers (e.g. SparseIoVec::read_columns_csc) use this to skip the triplet roundtrip when columns are already in memory.
Source§

fn cs_create(&mut self, key: CsKey, len: usize) -> Result<()>

Create a fixed-size 1-D backend dataset of len elements for the given CSC/CSR slot. No data is written yet.
Source§

fn cs_write_u64(&mut self, key: CsKey, offset: u64, data: &[u64]) -> Result<()>

Write a u64 slab at offset in the specified dataset. Used for CSC/CSR indices and indptr.
Source§

fn cs_write_f32(&mut self, key: CsKey, offset: u64, data: &[f32]) -> Result<()>

Write an f32 slab at offset in the specified dataset. Used for CSC/CSR data.
Source§

fn read_columns_ndarray(&self, columns: Self::IndexIter) -> Result<Array2<f32>>

Read columns within the range and return dense ndarray::Array2 Read more
Source§

fn read_columns_tensor(&self, columns: Self::IndexIter) -> Result<Tensor>

Read columns within the range and return dense candle_core::Tensor Read more
Source§

fn read_columns_dmatrix(&self, columns: Self::IndexIter) -> Result<DMatrix<f32>>

Read columns within the range and return dense nalgebrea::DMatrix Read more
Source§

fn read_columns_csr(&self, columns: Self::IndexIter) -> Result<CsrMatrix<f32>>

Read columns within the range and return sparse CsrMatrix Read more
Source§

fn read_columns_csc(&self, columns: Self::IndexIter) -> Result<CscMatrix<f32>>

Read columns within the range and return sparse CsrMatrix Read more
Source§

fn read_rows_ndarray(&self, rows: Self::IndexIter) -> Result<Array2<f32>>

Read rows within the range and return dense ndarray::Array2 Read more
Source§

fn read_rows_tensor(&self, rows: Self::IndexIter) -> Result<Tensor>

Read rows within the range and return dense candle_core::Tensor Read more
Source§

fn read_rows_dmatrix(&self, rows: Self::IndexIter) -> Result<DMatrix<f32>>

Read rows within the range and return dense nalgebra::DMatrix Read more
Source§

fn read_rows_csr(&self, rows: Self::IndexIter) -> Result<CsrMatrix<f32>>

Read rows within the range and return sparse CsrMatrix Read more
Source§

fn read_rows_csc(&self, rows: Self::IndexIter) -> Result<CscMatrix<f32>>

Read rows within the range and return sparse CscMatrix Read more
Source§

fn import_mtx_file(&mut self, mtx_file: &str, index_by_row: bool) -> Result<()>

Read an mtx file once and populate the backend: the column (CSC) index always, the row (CSR) index as well when index_by_row. Both are streamed out of the same triplet vector, so the file is inflated once and the triplets are the only full-size structure alive. Read more
Source§

fn import_dmatrix_by_row(&mut self, matrix: &DMatrix<f32>) -> Result<()>

Add dmatrix to zarr backend by row (CSR format) Read more
Source§

fn import_dmatrix_by_col(&mut self, matrix: &DMatrix<f32>) -> Result<()>

Add dmatrix to zarr backend by column (CSC format) Read more
Source§

fn import_ndarray_by_row(&mut self, array: &Array2<f32>) -> Result<()>

Add ndarray to zarr backend by row (CSR format) Read more
Source§

fn import_ndarray_by_col(&mut self, array: &Array2<f32>) -> Result<()>

Add ndarray to zarr backend by column (CSC format) Read more
Source§

fn column_nnz(&self, col: usize) -> Option<u64>

Exact nnz of one column, from the resident indptr — no I/O. Read more
Source§

fn subset_columns_rows( &mut self, columns: Option<&Vec<usize>>, rows: Option<&Vec<usize>>, ) -> Result<()>

Select the columns of the data and create a new backend file Read more
Source§

fn reorder_rows(&mut self, row_names_order: &[Box<str>]) -> Result<()>

Reposition rows in a new order specified by remap Read more
Source§

fn record_triplets_by_row( &mut self, row_col_val_triplets: &mut Vec<(u64, u64, f32)>, ) -> Result<()>

Stream the triplets out as CSR slabs; the row-major twin of record_triplets_by_col.
Source§

fn record_triplets_by_col( &mut self, row_col_val_triplets: &mut Vec<(u64, u64, f32)>, ) -> Result<()>

Stream the triplets out as CSC slabs. Read more
Source§

fn begin_streaming_csc(&mut self, shape: (usize, usize, usize)) -> Result<()>

Begin a streaming CSC build for a sparse matrix of known shape. Pre-creates /by_column/{data, indices, indptr} at their final sizes so subsequent append_csc_slab calls write into disjoint hyperslabs without further allocation.
Source§

fn append_csc_slab( &mut self, col_offset: u64, nnz_offset: u64, local_colptr: &[u64], row_indices: &[u64], values: &[f32], ) -> Result<()>

Append one contiguous CSC column band. Read more
Source§

fn finalize_streaming_csc(&mut self) -> Result<()>

Finalize CSC streaming by writing the final indptr sentinel at position ncol, equal to the total nnz.
Source§

fn begin_streaming_csr(&mut self, shape: (usize, usize, usize)) -> Result<()>

Begin a streaming CSR build for a sparse matrix of known shape; the row-major twin of begin_streaming_csc.
Source§

fn append_csr_slab( &mut self, row_offset: u64, nnz_offset: u64, local_rowptr: &[u64], col_indices: &[u64], values: &[f32], ) -> Result<()>

Append one contiguous CSR row band; the row-major twin of append_csc_slab, with the same audits. Read more
Source§

fn finalize_streaming_csr(&mut self) -> Result<()>

Finalize CSR streaming: write the indptr sentinel at position nrow, load the row index, and check the appended count against the declared nnz – the one violation the written indptr cannot reveal.
Source§

fn build_csr_from_csc_streaming(&mut self) -> Result<()>

Build /by_row/{data, indices, indptr} by transposing the already- written CSC data on disk. Uses two passes over CSC with bounded auxiliary memory (~24 B × nrow plus one row-band worth of CSR).

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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 = !

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

fn try_from(value: U) -> Result<T, !>

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more