pub struct CompressedSparseData2<T, U = T>{
pub data: Vec<T>,
pub indices: Vec<u32>,
pub indptr: Vec<u32>,
pub cs_type: CompressedSparseFormat,
pub data_2: Option<Vec<U>>,
pub shape: (usize, usize),
}Expand description
Structure to store compressed sparse data with two potential data layers. Think for example in single cell raw counts and normalised counts.
Fields§
§data: Vec<T>The first data slot for this compressed sparse data format
indices: Vec<u32>The indices of the data points
indptr: Vec<u32>The indptr of the data points
cs_type: CompressedSparseFormatEnum defining if the data is stored in CSC or CSR, see CompressedSparseFormat
data_2: Option<Vec<U>>Optional second data slot for a different layer of the data (for example raw and normalised counts)
shape: (usize, usize)Shape of the data (rows, cols)
Implementations§
Source§impl<T, U> CompressedSparseData2<T, U>where
T: BixverseNumeric + Serialize + DeserializeOwned,
U: BixverseNumeric + Serialize + DeserializeOwned,
impl<T, U> CompressedSparseData2<T, U>where
T: BixverseNumeric + Serialize + DeserializeOwned,
U: BixverseNumeric + Serialize + DeserializeOwned,
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, SparseErrors>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, SparseErrors>
Read a matrix written by Self::to_bytes.
The decoded structure is validated, since the bytes may come from disk.
§Params
bytes- The blob
§Returns
The matrix, or a header, decode or validation error.
Source§impl<T, U> CompressedSparseData2<T, U>where
T: BixverseNumeric,
U: BixverseNumeric,
impl<T, U> CompressedSparseData2<T, U>where
T: BixverseNumeric,
U: BixverseNumeric,
Sourcepub fn new_csc(
data: &[T],
indices: &[u32],
indptr: &[u32],
data2: Option<&[U]>,
shape: (usize, usize),
) -> Self
pub fn new_csc( data: &[T], indices: &[u32], indptr: &[u32], data2: Option<&[U]>, shape: (usize, usize), ) -> Self
Sourcepub fn new_csr(
data: &[T],
indices: &[u32],
indptr: &[u32],
data2: Option<&[U]>,
shape: (usize, usize),
) -> Self
pub fn new_csr( data: &[T], indices: &[u32], indptr: &[u32], data2: Option<&[U]>, shape: (usize, usize), ) -> Self
Sourcepub fn from_parts(
data: Vec<T>,
indices: Vec<u32>,
indptr: Vec<u32>,
data2: Option<Vec<U>>,
cs_type: CompressedSparseFormat,
shape: (usize, usize),
) -> Self
pub fn from_parts( data: Vec<T>, indices: Vec<u32>, indptr: Vec<u32>, data2: Option<Vec<U>>, cs_type: CompressedSparseFormat, shape: (usize, usize), ) -> Self
Take ownership of buffers that were built for this matrix
CompressedSparseData2::new_csr and its CSC sibling copy all three buffers, which doubles peak memory for any caller that assembled them itself and then throws the originals away.
§Params
data- The underlying data, moved.indices- The minor-axis indices, moved.indptr- The major-axis pointers, moved.data2- An optional second layer, moved.cs_type- Which orientation the buffers describe.shape-(nrow, ncol).
§Returns
The matrix, with no buffer copied.
Sourcepub fn transform_single_layer(
&self,
use_second_layer: bool,
) -> Result<Self, SparseErrors>
pub fn transform_single_layer( &self, use_second_layer: bool, ) -> Result<Self, SparseErrors>
Sourcepub fn transpose_and_convert(&self) -> Self
pub fn transpose_and_convert(&self) -> Self
Sourcepub fn from_upper_triangle_sym(
upper_triangle: &[T],
n: usize,
include_diagonal: bool,
format: CompressedSparseFormat,
) -> Selfwhere
T: BixverseNumeric + Float,
pub fn from_upper_triangle_sym(
upper_triangle: &[T],
n: usize,
include_diagonal: bool,
format: CompressedSparseFormat,
) -> Selfwhere
T: BixverseNumeric + Float,
Create a sparse matrix from an upper triangular matrix.
§Params
upper_triangle- The upper triangular matrix.n- The number of rows and columns in the matrix.include_diagonal- Whether to include the diagonal elements.format- The format of the sparse matrix, see CompressedSparseFormat.
§Returns
A sparse matrix.
Sourcepub fn get_data2_unsafe(&self) -> Vec<U>
pub fn get_data2_unsafe(&self) -> Vec<U>
Return the second layer
If this does not exist, the function will panic
§Returns
Vector of the second layer
Sourcepub fn to_sparse_axes(&self) -> Vec<SparseAxis<T, U>>
pub fn to_sparse_axes(&self) -> Vec<SparseAxis<T, U>>
Split into one owned SparseAxis per major-axis run.
Columns of a CSC or rows of a CSR. A layer that is empty (not populated) stays empty on every axis.
§Returns
The axes in order, each sized to the minor dimension.
Sourcepub fn slice_rows(&self, rows: &[usize]) -> Result<Self, SparseErrors>
pub fn slice_rows(&self, rows: &[usize]) -> Result<Self, SparseErrors>
Sourcepub fn slice_cols(&self, cols: &[usize]) -> Result<Self, SparseErrors>
pub fn slice_cols(&self, cols: &[usize]) -> Result<Self, SparseErrors>
Sourcepub fn from_entry_fn<G>(
nrows: usize,
ncols: usize,
format: CompressedSparseFormat,
get: G,
) -> Self
pub fn from_entry_fn<G>( nrows: usize, ncols: usize, format: CompressedSparseFormat, get: G, ) -> Self
Sourcepub fn validate(&self) -> Result<(), SparseErrors>
pub fn validate(&self) -> Result<(), SparseErrors>
Check every invariant that indexing this matrix relies on.
Self::assert_invariants is a debug_assert helper and compiles out
in release, and it never checks the indices against the minor axis.
This is the release-mode counterpart, for input that crossed an FFI
boundary: the fields are public, so a caller can hand over an indptr
that disagrees with shape or an index past the minor axis, and any
consumer that scatters into a dense buffer sized from shape would
then panic inside a worker thread or, worse, silently process fewer
major runs than the shape declares.
A layer that is empty is treated as absent rather than as a length
mismatch, since Self::transform_single_layer deliberately leaves the
unused layer empty.
§Returns
Ok(()), or the first invariant that failed:
SparseErrors::SparseIndptrInvalid for an indptr that disagrees
with shape or with the number of stored values,
SparseErrors::DimensionMisMatchSparse for a populated layer whose
length does not match indices, and
SparseErrors::SliceIndexOutOfBounds for an index past the minor
axis.
Sourcepub fn assert_invariants(&self)
pub fn assert_invariants(&self)
Assertion helper for invariants
Trait Implementations§
Source§impl<T, U> Clone for CompressedSparseData2<T, U>
impl<T, U> Clone for CompressedSparseData2<T, U>
Source§impl<T, U> Debug for CompressedSparseData2<T, U>
impl<T, U> Debug for CompressedSparseData2<T, U>
Source§impl<'de, T, U> Deserialize<'de> for CompressedSparseData2<T, U>
impl<'de, T, U> Deserialize<'de> for CompressedSparseData2<T, U>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl<T, U> Freeze for CompressedSparseData2<T, U>
impl<T, U> RefUnwindSafe for CompressedSparseData2<T, U>
impl<T, U> Send for CompressedSparseData2<T, U>
impl<T, U> Sync for CompressedSparseData2<T, U>
impl<T, U> Unpin for CompressedSparseData2<T, U>
impl<T, U> UnsafeUnpin for CompressedSparseData2<T, U>
impl<T, U> UnwindSafe for CompressedSparseData2<T, U>
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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