Skip to main content

CscMatrix

Struct CscMatrix 

Source
pub struct CscMatrix<T: Real = f64> {
    pub n_rows: usize,
    pub col_ptr: Vec<usize>,
    pub row_idx: Vec<u32>,
    pub val: Vec<T>,
}
Expand description

Sparse matrix in compressed sparse column (CSC) format.

See the module documentation for the invariants. Equality is structural (same dimensions, same stored entries in the same order), which for matrices satisfying the invariants is equality of the matrices.

Fields§

§n_rows: usize

Number of rows m.

§col_ptr: Vec<usize>

Column pointers, length n + 1; column j occupies col_ptr[j]..col_ptr[j + 1].

§row_idx: Vec<u32>

Row index of each stored entry, strictly increasing within a column.

§val: Vec<T>

Value of each stored entry; finite and nonzero.

Implementations§

Source§

impl<T: Real> CscMatrix<T>

Source

pub fn new(n_rows: usize, n_cols: usize) -> Self

The m × n zero matrix (the contract’s name; the same as CscMatrix::zeros).

§Panics

If m or n exceeds u32::MAX.

Source

pub fn zeros(n_rows: usize, n_cols: usize) -> Self

The m × n zero matrix.

§Panics

If m or n exceeds u32::MAX.

Source

pub fn from_raw_parts( n_rows: usize, col_ptr: Vec<usize>, row_idx: Vec<u32>, val: Vec<T>, ) -> Result<Self, SparseError>

Builds a matrix from raw compressed arrays, validating every invariant.

Source

pub fn from_triplets( n_rows: usize, n_cols: usize, triplets: &[(Row, Col, T)], ) -> Result<Self, SparseError>

Builds an m × n matrix from triplets (i, j, v) by Algorithm C: duplicates are summed in input order and exact zeros are dropped.

Source

pub fn n_rows(&self) -> usize

Number of rows m.

Source

pub fn n_cols(&self) -> usize

Number of columns n.

Source

pub fn nnz(&self) -> usize

Number of stored entries.

Source

pub fn col(&self, j: Col) -> (&[u32], &[T])

Row indices and values of column j.

Source

pub fn get(&self, i: Row, j: Col) -> T

Entry a_ij, or 0 if not stored; O(log nnz(column j)).

Source

pub fn gaxpy(&self, alpha: T, x: &[T], y: &mut [T])

y ← y + α A x with dense x (length n) and y (length m), column by column: y_i ← y_i + a_ij (α x_j) for the stored entries, skipping the columns with x_j = 0.

§Panics

If x.len() != n or y.len() != m.

Source

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

The same matrix in row-wise (CSR) storage, by Algorithm T.

Source

pub fn transpose(&self) -> CscMatrix<T>

The transpose Aᵀ in CSC storage, by Algorithm T.

Source

pub fn check_invariants(&self) -> Result<(), SparseError>

Checks invariants (C1)–(C4).

Source§

impl<T: Real> CscMatrix<T>

Source

pub fn pattern(&self) -> Pattern

The structure without values, consumed by the orderings (Chapter 5.9).

Source

pub fn symmetric_pattern(&self) -> Result<Pattern, SparseError>

The pattern of A + Aᵀ (Algorithm S) for the symmetric orderings; an error unless A is square.

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> Self

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: Real> ColumnSource<T> for CscMatrix<T>

An explicit square matrix B.

Source§

fn m(&self) -> usize

Order m of B (its number of columns).
Source§

fn for_each_entry<F: FnMut(u32, T)>(&self, k: usize, f: F)

Calls f(i, b_ik) for every stored entry of column k, rows increasing for structural columns.
Source§

fn nnz_hint(&self) -> usize

Upper bound on the nonzeros of B (an allocation hint).
Source§

fn validate(&self) -> Result<(), SparseError>

Checks that the source describes a square m × m matrix whose references are in range (invariant (B1)).
Source§

impl<T: Debug + Real> Debug for CscMatrix<T>

Source§

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

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

impl<T: PartialEq + Real> PartialEq for CscMatrix<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq + Real> StructuralPartialEq for CscMatrix<T>

Auto Trait Implementations§

§

impl<T> Forget for CscMatrix<T>

§

impl<T> Freeze for CscMatrix<T>
where Vec<T>: Freeze,

§

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

§

impl<T> Send for CscMatrix<T>
where Vec<T>: Send,

§

impl<T> Sync for CscMatrix<T>
where Vec<T>: Sync,

§

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

§

impl<T> UnsafeUnpin for CscMatrix<T>
where Vec<T>: UnsafeUnpin,

§

impl<T> UnwindSafe for CscMatrix<T>
where Vec<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> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

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