CsrMatrixSet

Struct CsrMatrixSet 

Source
pub struct CsrMatrixSet<T> { /* private fields */ }
Expand description

A collection of CSR matrices stored efficiently in a single data structure.

This structure is designed to store multiple CSR matrices with different dimensions in a compact format. It’s particularly useful for applications that need to manage many sparse matrices with similar sparsity patterns or for systems that generate multiple matrices during computation.

§Format

The set stores all matrices in contiguous arrays:

  • col_indices: Column indices for all matrices concatenated
  • values: Non-zero values for all matrices concatenated
  • row_offsets: Row offsets for all matrices concatenated
  • ncols: Number of columns for each individual matrix
  • partition: Metadata to locate each matrix within the concatenated data

§Examples

use algebra_sparse::CsrMatrixSet;
use algebra_sparse::traits::IntoView;
use algebra_sparse::CsrMatrixSetMethods;

let mut set: CsrMatrixSet<f64> = CsrMatrixSet::default();

// Add first matrix to the set
{
    let mut builder1 = set.new_matrix(3, 1e-10);
    builder1.new_row().push(0, 1.0);
} // builder1 is dropped here and matrix is added to set

// Add second matrix to the set
{
    let mut builder2 = set.new_matrix(2, 1e-10);
    builder2.new_row().push(1, 3.0);
} // builder2 is dropped here and matrix is added to set

println!("Set contains {} matrices", (&set).len());

Implementations§

Source§

impl<T: Real> CsrMatrixSet<T>

Source

pub fn clear(&mut self)

Clears all matrices from the set.

This removes all data and allows reuse of the set.

Source

pub fn new_matrix( &mut self, ncol: usize, zero_threshold: T, ) -> CsrMatrixBuilder<'_, T>

Creates a new matrix builder for this set.

The matrix will be automatically added to the set when the builder is dropped.

§Arguments
  • ncol - Number of columns for the new matrix
  • zero_threshold - Values below this threshold are filtered out
§Returns

A CsrMatrixBuilder for constructing the new matrix

Source§

impl<T> CsrMatrixSet<T>

Source

pub fn get(&self, index: usize) -> CsrMatrixView<'_, T>

Returns the view of the matrix at the given index.

§Arguments
  • index - Index of the matrix to retrieve
§Returns

A CsrMatrixView representing the requested matrix

§Panics

Panics if the index is out of bounds

Source

pub fn as_view(&self) -> CsrMatrixSetView<'_, T>

Returns a view of the entire matrix set.

Trait Implementations§

Source§

impl<T: Clone> Clone for CsrMatrixSet<T>

Source§

fn clone(&self) -> CsrMatrixSet<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Default for CsrMatrixSet<T>

Source§

fn default() -> Self

Creates a new empty CSR matrix set.

Source§

impl<'a, T> IntoView for &'a CsrMatrixSet<T>

Source§

type View = CsrMatrixSetView<'a, T>

The view type produced by this trait.
Source§

fn into_view(self) -> Self::View

Converts the type into an immutable view. Read more

Auto Trait Implementations§

§

impl<T> Freeze for CsrMatrixSet<T>

§

impl<T> RefUnwindSafe for CsrMatrixSet<T>
where T: RefUnwindSafe,

§

impl<T> Send for CsrMatrixSet<T>
where T: Send,

§

impl<T> Sync for CsrMatrixSet<T>
where T: Sync,

§

impl<T> Unpin for CsrMatrixSet<T>
where T: Unpin,

§

impl<T> UnwindSafe for CsrMatrixSet<T>
where T: UnwindSafe,

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