Skip to main content

CsrMatrix

Struct CsrMatrix 

Source
pub struct CsrMatrix {
    pub nrows: usize,
    pub ncols: usize,
    pub indptr: Vec<usize>,
    pub indices: Vec<usize>,
    pub data: Vec<f64>,
}
Expand description

Compressed sparse rows: the entries of row i are indices[indptr[i]..indptr[i+1]] (columns, increasing) and the matching data (SciPy’s csr_array).

Fields§

§nrows: usize§ncols: usize§indptr: Vec<usize>§indices: Vec<usize>§data: Vec<f64>

Implementations§

Source§

impl CsrMatrix

Source

pub fn from_triplets( nrows: usize, ncols: usize, rows: &[usize], cols: &[usize], values: &[f64], ) -> Result<Self>

Builds a CSR matrix from triplets, summing duplicates and sorting the column indices of each row: a counting sort by row, then by column within each row.

Source

pub fn from_dense(a: &Array2<f64>, tol: f64) -> Self

The entries of a larger than tol in magnitude.

Source

pub fn identity(n: usize) -> Self

The n × n identity.

Source

pub fn diags( diagonals: &[Vec<f64>], offsets: &[isize], nrows: usize, ncols: usize, ) -> Result<Self>

A matrix with the given diagonals (SciPy’s diags): diagonals[k] holds the values of the diagonal at offsets[k] (0 main, positive above), starting from its first element.

Source

pub fn nnz(&self) -> usize

Source

pub fn to_dense(&self) -> Array2<f64>

Source

pub fn get(&self, i: usize, j: usize) -> f64

The entry at (i, j) (zero if not stored).

Source

pub fn matvec(&self, x: &[f64]) -> Vec<f64>

A x.

Source

pub fn rmatvec(&self, x: &[f64]) -> Vec<f64>

Aᵀ x.

Source

pub fn transpose(&self) -> CsrMatrix

The transpose, again in CSR form.

Source

pub fn to_csc(&self) -> CscMatrix

The same matrix in CSC form.

Source

pub fn matmul(&self, b: &CsrMatrix) -> Result<CsrMatrix>

A B by Gustavson’s row-by-row algorithm.

Source

pub fn add(&self, alpha: f64, b: &CsrMatrix, beta: f64) -> Result<CsrMatrix>

α A + β B.

Source

pub fn diagonal(&self) -> Vec<f64>

The main diagonal.

Trait Implementations§

Source§

impl Clone for CsrMatrix

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

Source§

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

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

impl LinearOperator for CsrMatrix

Source§

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

(rows, columns).
Source§

fn matvec(&self, x: &[f64]) -> Vec<f64>

A x.
Source§

fn rmatvec(&self, x: &[f64]) -> Vec<f64>

Aᵀ x (needed by LSQR).
Source§

impl PartialEq for CsrMatrix

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 StructuralPartialEq for CsrMatrix

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