Skip to main content

CompressedSparseData2

Struct CompressedSparseData2 

Source
pub struct CompressedSparseData2<T, U = T>
where T: Clone, U: Clone,
{ 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: CompressedSparseFormat

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

Source

pub fn new_csc( data: &[T], indices: &[u32], indptr: &[u32], data2: Option<&[U]>, shape: (usize, usize), ) -> CompressedSparseData2<T, U>

Generate a nes CSC version of the matrix

§Params
  • data - The underlying data
  • indices - The index positions (in this case row indices)
  • indptr - The index pointer (in this case the column index pointers)
  • data2 - An optional second layer
  • shape - (nrow, ncol).
§Returns

Self as a CSC-type matrix

Source

pub fn new_csr( data: &[T], indices: &[u32], indptr: &[u32], data2: Option<&[U]>, shape: (usize, usize), ) -> CompressedSparseData2<T, U>

Generate a nes CSR version of the matrix

§Params
  • data - The underlying data
  • indices - The index positions (in this case row indices)
  • indptr - The index pointer (in this case the column index pointers)
  • data2 - An optional second layer
  • shape - (nrow, ncol).
§Returns

Self as a CSR-type matrix

Source

pub fn from_parts( data: Vec<T>, indices: Vec<u32>, indptr: Vec<u32>, data2: Option<Vec<U>>, cs_type: CompressedSparseFormat, shape: (usize, usize), ) -> CompressedSparseData2<T, U>

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.

Source

pub fn transform(&self) -> CompressedSparseData2<T, U>

Transform from CSC to CSR or vice versa

§Returns

The transformed/transposed version

Source

pub fn transform_single_layer( &self, use_second_layer: bool, ) -> Result<CompressedSparseData2<T, U>, CoreErrors>

Transform from CSC to CSR or vice versa, keeping only one data layer.

§Params
  • use_second_layer - If true, the output keeps data_2 and data is empty. If false, the output keeps data and data_2 is None.
§Returns

The transformed/transposed version with only the requested layer.

Source

pub fn transpose_and_convert(&self) -> CompressedSparseData2<T, U>

Transpose and convert

§Returns

The transformed/transposed version

Source

pub fn from_dense_matrix( mat: Mat<Ref<'_, T>>, format: CompressedSparseFormat, ) -> CompressedSparseData2<T, U>
where T: BixverseFloat,

Generates a sparse matrix from a dense matrix

§Params
  • mat: The dense matrix to convert to a sparse matrix
  • format: The format of the sparse matrix to generate
§Returns
  • Self: The sparse matrix generated from the dense matrix
Source

pub fn from_upper_triangle_sym( upper_triangle: &[T], n: usize, include_diagonal: bool, format: CompressedSparseFormat, ) -> CompressedSparseData2<T, U>
where T: BixverseFloat,

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.

Source

pub fn shape(&self) -> (usize, usize)

Returns the shape of the matrix

§Returns

A tuple of (n_row, n_col)

Source

pub fn nrows(&self) -> usize

Return the number of rows

§Returns

Number of rows

Source

pub fn ncols(&self) -> usize

Return the number of columns

§Returns

Number of columns

Source

pub fn get_nnz(&self) -> usize

Returns the NNZ

§Returns

The number of NNZ

Source

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

Source

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.

Source

pub fn slice_rows( &self, rows: &[usize], ) -> Result<CompressedSparseData2<T, U>, CoreErrors>

Slice the rows of the matrix

§Params
  • rows - The row indices to keep
§Returns

Self with the rows to keep

Source

pub fn slice_cols( &self, cols: &[usize], ) -> Result<CompressedSparseData2<T, U>, CoreErrors>

Slice the columns of the matrix

§Params
  • cols - The column indices to keep
§Returns

Self with the cols to keep

Source

pub fn slice( &self, rows: &[usize], cols: &[usize], ) -> Result<CompressedSparseData2<T, U>, CoreErrors>

Slice across rows and columns

§Params
  • rows - The row indices to keep
  • cols - The column indices to keep
§Returns

Self with the rows and columns to keep

Source

pub fn validate(&self) -> Result<(), CoreErrors>

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: CoreErrors::SparseIndptrInvalid for an indptr that disagrees with shape or with the number of stored values, CoreErrors::DimensionMisMatchSparse for a populated layer whose length does not match indices, and CoreErrors::SliceIndexOutOfBounds for an index past the minor axis.

Source

pub fn assert_invariants(&self)

Assertion helper for invariants

Trait Implementations§

Source§

impl<T, U> Clone for CompressedSparseData2<T, U>
where T: Clone, U: Clone,

Source§

fn clone(&self) -> CompressedSparseData2<T, U>

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<T, U> Debug for CompressedSparseData2<T, U>
where T: Debug + Clone, U: Debug + Clone,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, U> Freeze for CompressedSparseData2<T, U>
where Vec<T>: Freeze, Option<Vec<U>>: Freeze,

§

impl<T, U> RefUnwindSafe for CompressedSparseData2<T, U>

§

impl<T, U> Send for CompressedSparseData2<T, U>
where Vec<T>: Send, Option<Vec<U>>: Send,

§

impl<T, U> Sync for CompressedSparseData2<T, U>
where Vec<T>: Sync, Option<Vec<U>>: Sync,

§

impl<T, U> Unpin for CompressedSparseData2<T, U>
where Vec<T>: Unpin, Option<Vec<U>>: Unpin,

§

impl<T, U> UnsafeUnpin for CompressedSparseData2<T, U>

§

impl<T, U> UnwindSafe for CompressedSparseData2<T, U>

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> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

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> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

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