CscMatrix

Struct CscMatrix 

Source
pub struct CscMatrix<T: Scalar> { /* private fields */ }
Expand description

Compressed Sparse Column matrix.

Efficient for:

  • Column slicing
  • Matrix-vector products with transpose (y = A^T * x)
  • Column-wise traversal
  • Direct solvers (LU, Cholesky)

Implementations§

Source§

impl<T: Scalar + Clone> CscMatrix<T>

Source

pub fn new( nrows: usize, ncols: usize, col_ptrs: Vec<usize>, row_indices: Vec<usize>, values: Vec<T>, ) -> Result<Self, CscError>

Creates a new CSC matrix from raw components.

§Arguments
  • nrows - Number of rows
  • ncols - Number of columns
  • col_ptrs - Column pointers (length ncols + 1)
  • row_indices - Row indices for each non-zero
  • values - Non-zero values
§Errors

Returns an error if the input is invalid.

Source

pub unsafe fn new_unchecked( nrows: usize, ncols: usize, col_ptrs: Vec<usize>, row_indices: Vec<usize>, values: Vec<T>, ) -> Self

Creates a CSC matrix without validation (unsafe but faster).

§Safety

The caller must ensure:

  • col_ptrs.len() == ncols + 1
  • values.len() == row_indices.len()
  • col_ptrs is monotonically increasing
  • All row indices are < nrows
Source

pub fn zeros(nrows: usize, ncols: usize) -> Self

Creates an empty CSC matrix with given dimensions.

Source

pub fn eye(n: usize) -> Self
where T: Field,

Creates an identity matrix in CSC format.

Source

pub fn nrows(&self) -> usize

Returns the number of rows.

Source

pub fn ncols(&self) -> usize

Returns the number of columns.

Source

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

Returns the shape (nrows, ncols).

Source

pub fn nnz(&self) -> usize

Returns the number of non-zero elements.

Source

pub fn density(&self) -> f64

Returns the density (nnz / total_elements).

Source

pub fn col_ptrs(&self) -> &[usize]

Returns a reference to the column pointers.

Source

pub fn row_indices(&self) -> &[usize]

Returns a reference to the row indices.

Source

pub fn values(&self) -> &[T]

Returns a reference to the values.

Source

pub fn values_mut(&mut self) -> &mut [T]

Returns a mutable reference to the values.

Source

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

Gets the value at (row, col), returning None if not present.

Source

pub fn get_or_zero(&self, row: usize, col: usize) -> T
where T: Field,

Gets the value at (row, col), returning zero if not present.

Source

pub fn col_iter(&self, col: usize) -> impl Iterator<Item = (usize, &T)>

Returns an iterator over the non-zeros in a column.

Source

pub fn iter(&self) -> impl Iterator<Item = (usize, usize, &T)>

Returns an iterator over all non-zeros as (row, col, value).

Source

pub fn to_csr(&self) -> CsrMatrix<T>

Converts to CSR format.

Source

pub fn to_dense(&self) -> Mat<T>
where T: Field + Zeroable,

Converts to dense matrix.

Source

pub fn from_dense(dense: &MatRef<'_, T>) -> Self
where T: Field,

Creates a CSC matrix from a dense matrix.

Source

pub fn transpose(&self) -> Self

Returns the transpose of this matrix.

Source

pub fn scale(&mut self, alpha: T)

Scales all values by a scalar.

Source

pub fn scaled(&self, alpha: T) -> Self

Returns a scaled copy of this matrix.

Source

pub fn col_nnz(&self, col: usize) -> usize

Returns the number of non-zeros in a column.

Source

pub fn is_structurally_symmetric(&self) -> bool

Checks if the matrix is structurally symmetric.

Returns true if A[i,j] != 0 implies A[j,i] != 0.

Trait Implementations§

Source§

impl<T: Clone + Scalar> Clone for CscMatrix<T>

Source§

fn clone(&self) -> CscMatrix<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: Debug + Scalar> Debug for CscMatrix<T>

Source§

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

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

impl<T> Index<(usize, usize)> for CscMatrix<T>
where T: Field + Scalar + Clone,

Source§

type Output = T

The returned type after indexing.
Source§

fn index(&self, (row, col): (usize, usize)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for CscMatrix<T>

§

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

§

impl<T> Send for CscMatrix<T>

§

impl<T> Sync for CscMatrix<T>

§

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

§

impl<T> UnwindSafe for CscMatrix<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> 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.