SparseMatrix

Struct SparseMatrix 

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

Main sparse matrix implementation supporting multiple storage formats.

Implementations§

Source§

impl SparseMatrix

Source

pub fn from_triplets( triplets: Vec<(usize, usize, Precision)>, rows: DimensionType, cols: DimensionType, ) -> Result<Self>

Create a new sparse matrix from coordinate (triplet) format.

§Arguments
  • triplets - Vector of (row, col, value) triplets
  • rows - Number of rows
  • cols - Number of columns
§Example
use sublinear_solver::SparseMatrix;
 
let matrix = SparseMatrix::from_triplets(
    vec![(0, 0, 4.0), (0, 1, 1.0), (1, 0, 2.0), (1, 1, 5.0)],
    2, 2
).unwrap();
Source

pub fn from_dense( data: &[Precision], rows: DimensionType, cols: DimensionType, ) -> Result<Self>

Create a sparse matrix from dense row-major data.

Zero elements are automatically filtered out.

Source

pub fn identity(size: DimensionType) -> Result<Self>

Create an identity matrix of the given size.

Source

pub fn diagonal(diag: &[Precision]) -> Result<Self>

Create a diagonal matrix from the given diagonal values.

Source

pub fn convert_to_format(&mut self, new_format: SparseFormat) -> Result<()>

Convert the matrix to a different storage format.

This operation may be expensive for large matrices.

Source

pub fn to_triplets(&self) -> Result<Vec<(usize, usize, Precision)>>

Extract the matrix as coordinate triplets.

Source

pub fn format(&self) -> SparseFormat

Get the current storage format.

Source

pub fn as_csr(&mut self) -> Result<&CSRStorage>

Get a reference to the underlying CSR storage.

Converts to CSR format if necessary.

Source

pub fn as_csc(&mut self) -> Result<&CSCStorage>

Get a reference to the underlying CSC storage.

Converts to CSC format if necessary.

Source

pub fn as_graph(&mut self) -> Result<&GraphStorage>

Get a reference to the underlying graph storage.

Converts to graph format if necessary.

Source

pub fn scale(&mut self, factor: Precision)

Scale the matrix by a scalar value.

Source

pub fn add_diagonal(&mut self, alpha: Precision) -> Result<()>

Add a scalar multiple of the identity matrix: A = A + alpha * I

Trait Implementations§

Source§

impl Clone for SparseMatrix

Source§

fn clone(&self) -> SparseMatrix

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 Debug for SparseMatrix

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SparseMatrix

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for SparseMatrix

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Matrix for SparseMatrix

Source§

fn rows(&self) -> DimensionType

Get the number of rows in the matrix.
Source§

fn cols(&self) -> DimensionType

Get the number of columns in the matrix.
Source§

fn get(&self, row: usize, col: usize) -> Option<Precision>

Get a specific matrix element, returning None if it’s zero or out of bounds.
Source§

fn row_iter( &self, row: usize, ) -> Box<dyn Iterator<Item = (IndexType, Precision)> + '_>

Get an iterator over non-zero elements in a specific row. Returns (column_index, value) pairs.
Source§

fn col_iter( &self, col: usize, ) -> Box<dyn Iterator<Item = (IndexType, Precision)> + '_>

Get an iterator over non-zero elements in a specific column. Returns (row_index, value) pairs.
Source§

fn multiply_vector( &self, x: &[Precision], result: &mut [Precision], ) -> Result<()>

Perform matrix-vector multiplication: result = A * x
Source§

fn multiply_vector_add( &self, x: &[Precision], result: &mut [Precision], ) -> Result<()>

Perform matrix-vector multiplication with accumulation: result += A * x
Source§

fn is_diagonally_dominant(&self) -> bool

Check if the matrix is diagonally dominant. A matrix is diagonally dominant if |a_ii| >= Σ_{j≠i} |a_ij| for all i.
Source§

fn diagonal_dominance_factor(&self) -> Option<Precision>

Get the diagonal dominance factor (minimum ratio of diagonal to off-diagonal).
Source§

fn nnz(&self) -> usize

Get the number of non-zero elements.
Source§

fn sparsity_info(&self) -> SparsityInfo

Get sparsity pattern information.
Source§

fn conditioning_info(&self) -> ConditioningInfo

Get matrix conditioning information.
Source§

fn format_name(&self) -> &'static str

Get the storage format name.
Source§

fn is_square(&self) -> bool

Check if the matrix is square.
Source§

fn frobenius_norm(&self) -> Precision

Get the Frobenius norm of the matrix.
Source§

fn spectral_radius_estimate(&self) -> Precision

Estimate the spectral radius (largest eigenvalue magnitude). Uses Gershgorin circle theorem for a conservative estimate.
Source§

impl Serialize for SparseMatrix

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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<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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,