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
impl SparseMtxData
Sourcepub fn new(zarr_file: Option<&str>) -> Result<Self>
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
Sourcepub fn open(backend_file: &str) -> Result<Self>
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)
Sourcepub fn from_mtx_file(
mtx_file: &str,
backend_file: Option<&str>,
index_by_row: Option<bool>,
) -> Result<Self>
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 backendbackend_file: zarr file to be associated withindex_by_row: if true, the matrix will be indexed by row
Sourcepub fn from_ndarray(
array: &Array2<f32>,
zarr_file: Option<&str>,
index_by_row: Option<bool>,
) -> Result<Self>
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 backendbackend_file- Optional zarr backend fileindex_by_row- Optional flag to index by row (CSR format)
Sourcepub fn from_dmatrix(
matrix: &DMatrix<f32>,
zarr_file: Option<&str>,
index_by_row: Option<bool>,
) -> Result<Self>
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 backendbackend_file- Optional zarr backend fileindex_by_row- Optional flag to index by row (CSR format)
Sourcepub fn print_hierarchy(&self) -> Result<()>
pub fn print_hierarchy(&self) -> Result<()>
Show the hierarchy of the zarr store
Trait Implementations§
Source§impl Clone for SparseMtxData
impl Clone for SparseMtxData
Source§impl SparseIo for SparseMtxData
impl SparseIo for SparseMtxData
Source§fn read_row_indptr(&mut self) -> Result<()>
fn read_row_indptr(&mut self) -> Result<()>
Read row index pointers
Source§fn column_indptr(&self) -> &[u64]
fn column_indptr(&self) -> &[u64]
Read column index pointers
Source§fn preload_columns(&mut self) -> Result<()>
fn preload_columns(&mut self) -> Result<()>
preload columns’ values and indices
Source§fn preload_rows(&mut self) -> Result<()>
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<()>
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<()>
fn initialize_backend(&mut self) -> Result<()>
Helper function to create a new zarr backend file
Source§fn remove_backend_file(&self) -> Result<()>
fn remove_backend_file(&self) -> Result<()>
Clean up the backend file
Source§fn get_backend_file_name(&self) -> &str
fn get_backend_file_name(&self) -> &str
Access file name of the zarr backend
Source§fn to_mtx_file(&self, mtx_file: &str) -> Result<()>
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)
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>])
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)
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>])
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_columns(&self) -> Option<usize>
fn num_columns(&self) -> Option<usize>
Number of columns in the matrix
Source§fn num_non_zeros(&self) -> Option<usize>
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<()>
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 namename_file: a file each line contains name wordsname_columns: range of columns to be used for namename_sep: separator for name columns
Source§fn register_names_vec(&mut self, key: &str, names: &[Box<str>]) -> Result<()>
fn register_names_vec(&mut self, key: &str, names: &[Box<str>]) -> Result<()>
Add arbitrary names (a vector of strings)
group_name: group namenames: a file each line contains name words
Source§fn retrieve_registered_names(&self, key: &str) -> Result<Vec<Box<str>>>
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)>)>
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)>)>
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)>)>
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<()>
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<()>
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)type IndexIter = Vec<usize>
Source§fn reopen_backend(&mut self) -> Result<()>
fn reopen_backend(&mut self) -> Result<()>
Source§fn read_column_indptr(&mut self) -> Result<()>
fn read_column_indptr(&mut self) -> Result<()>
Source§fn clean_preloaded_columns(&mut self)
fn clean_preloaded_columns(&mut self)
Source§fn clean_preloaded_rows(&mut self)
fn clean_preloaded_rows(&mut self)
Source§fn backend_type(&self) -> SparseIoBackend
fn backend_type(&self) -> SparseIoBackend
fn row_names(&self) -> Result<Vec<Box<str>>>
fn column_names(&self) -> Result<Vec<Box<str>>>
Source§fn csc_column_arrays(&self) -> Option<(&[u64], &[u64], &[f32])>
fn csc_column_arrays(&self) -> Option<(&[u64], &[u64], &[f32])>
(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<()>
fn cs_create(&mut self, key: CsKey, len: usize) -> Result<()>
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<()>
fn cs_write_u64(&mut self, key: CsKey, offset: u64, data: &[u64]) -> Result<()>
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<()>
fn cs_write_f32(&mut self, key: CsKey, offset: u64, data: &[f32]) -> Result<()>
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>>
fn read_columns_ndarray(&self, columns: Self::IndexIter) -> Result<Array2<f32>>
ndarray::Array2 Read moreSource§fn read_columns_tensor(&self, columns: Self::IndexIter) -> Result<Tensor>
fn read_columns_tensor(&self, columns: Self::IndexIter) -> Result<Tensor>
candle_core::Tensor Read moreSource§fn read_columns_dmatrix(&self, columns: Self::IndexIter) -> Result<DMatrix<f32>>
fn read_columns_dmatrix(&self, columns: Self::IndexIter) -> Result<DMatrix<f32>>
nalgebrea::DMatrix Read moreSource§fn read_columns_csr(&self, columns: Self::IndexIter) -> Result<CsrMatrix<f32>>
fn read_columns_csr(&self, columns: Self::IndexIter) -> Result<CsrMatrix<f32>>
CsrMatrix Read moreSource§fn read_columns_csc(&self, columns: Self::IndexIter) -> Result<CscMatrix<f32>>
fn read_columns_csc(&self, columns: Self::IndexIter) -> Result<CscMatrix<f32>>
CsrMatrix Read moreSource§fn read_rows_ndarray(&self, rows: Self::IndexIter) -> Result<Array2<f32>>
fn read_rows_ndarray(&self, rows: Self::IndexIter) -> Result<Array2<f32>>
ndarray::Array2 Read moreSource§fn read_rows_tensor(&self, rows: Self::IndexIter) -> Result<Tensor>
fn read_rows_tensor(&self, rows: Self::IndexIter) -> Result<Tensor>
candle_core::Tensor Read moreSource§fn read_rows_dmatrix(&self, rows: Self::IndexIter) -> Result<DMatrix<f32>>
fn read_rows_dmatrix(&self, rows: Self::IndexIter) -> Result<DMatrix<f32>>
nalgebra::DMatrix Read moreSource§fn read_rows_csr(&self, rows: Self::IndexIter) -> Result<CsrMatrix<f32>>
fn read_rows_csr(&self, rows: Self::IndexIter) -> Result<CsrMatrix<f32>>
CsrMatrix Read moreSource§fn read_rows_csc(&self, rows: Self::IndexIter) -> Result<CscMatrix<f32>>
fn read_rows_csc(&self, rows: Self::IndexIter) -> Result<CscMatrix<f32>>
CscMatrix Read moreSource§fn import_mtx_file(&mut self, mtx_file: &str, index_by_row: bool) -> Result<()>
fn import_mtx_file(&mut self, mtx_file: &str, index_by_row: bool) -> Result<()>
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 moreSource§fn import_dmatrix_by_row(&mut self, matrix: &DMatrix<f32>) -> Result<()>
fn import_dmatrix_by_row(&mut self, matrix: &DMatrix<f32>) -> Result<()>
Source§fn import_dmatrix_by_col(&mut self, matrix: &DMatrix<f32>) -> Result<()>
fn import_dmatrix_by_col(&mut self, matrix: &DMatrix<f32>) -> Result<()>
Source§fn import_ndarray_by_row(&mut self, array: &Array2<f32>) -> Result<()>
fn import_ndarray_by_row(&mut self, array: &Array2<f32>) -> Result<()>
Source§fn import_ndarray_by_col(&mut self, array: &Array2<f32>) -> Result<()>
fn import_ndarray_by_col(&mut self, array: &Array2<f32>) -> Result<()>
Source§fn column_nnz(&self, col: usize) -> Option<u64>
fn column_nnz(&self, col: usize) -> Option<u64>
Source§fn subset_columns_rows(
&mut self,
columns: Option<&Vec<usize>>,
rows: Option<&Vec<usize>>,
) -> Result<()>
fn subset_columns_rows( &mut self, columns: Option<&Vec<usize>>, rows: Option<&Vec<usize>>, ) -> Result<()>
Source§fn reorder_rows(&mut self, row_names_order: &[Box<str>]) -> Result<()>
fn reorder_rows(&mut self, row_names_order: &[Box<str>]) -> Result<()>
remap Read moreSource§fn record_triplets_by_row(
&mut self,
row_col_val_triplets: &mut Vec<(u64, u64, f32)>,
) -> Result<()>
fn record_triplets_by_row( &mut self, row_col_val_triplets: &mut Vec<(u64, u64, f32)>, ) -> Result<()>
record_triplets_by_col.Source§fn record_triplets_by_col(
&mut self,
row_col_val_triplets: &mut Vec<(u64, u64, f32)>,
) -> Result<()>
fn record_triplets_by_col( &mut self, row_col_val_triplets: &mut Vec<(u64, u64, f32)>, ) -> Result<()>
Source§fn begin_streaming_csc(&mut self, shape: (usize, usize, usize)) -> Result<()>
fn begin_streaming_csc(&mut self, shape: (usize, usize, usize)) -> Result<()>
/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<()>
fn append_csc_slab( &mut self, col_offset: u64, nnz_offset: u64, local_colptr: &[u64], row_indices: &[u64], values: &[f32], ) -> Result<()>
Source§fn finalize_streaming_csc(&mut self) -> Result<()>
fn finalize_streaming_csc(&mut self) -> Result<()>
ncol, equal to the total nnz.Source§fn begin_streaming_csr(&mut self, shape: (usize, usize, usize)) -> Result<()>
fn begin_streaming_csr(&mut self, shape: (usize, usize, usize)) -> Result<()>
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<()>
fn append_csr_slab( &mut self, row_offset: u64, nnz_offset: u64, local_rowptr: &[u64], col_indices: &[u64], values: &[f32], ) -> Result<()>
append_csc_slab, with the same audits. Read moreSource§fn finalize_streaming_csr(&mut self) -> Result<()>
fn finalize_streaming_csr(&mut self) -> Result<()>
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<()>
fn build_csr_from_csc_streaming(&mut self) -> Result<()>
/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§
impl !RefUnwindSafe for SparseMtxData
impl !UnwindSafe for SparseMtxData
impl Freeze for SparseMtxData
impl Send for SparseMtxData
impl Sync for SparseMtxData
impl Unpin for SparseMtxData
impl UnsafeUnpin for SparseMtxData
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.