Skip to main content

CsrMatrix

Struct CsrMatrix 

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

Compressed-sparse-row matrix.

Stores only the non-zero entries data together with their column indices indices (per row, in ascending column order) and the CSR row-pointer indptr (length nrows + 1). A zero entry must not be stored.

Implementations§

Source§

impl CsrMatrix

Source

pub fn nrows(&self) -> usize

Number of rows.

Source

pub fn ncols(&self) -> usize

Number of columns.

Source

pub fn from_dense(dense: &[f64], nrows: usize, ncols: usize) -> Self

Build a CSR matrix from a dense row-major slice (row length ncols). Zero entries are dropped.

Source

pub fn nnz(&self) -> usize

Number of explicitly stored non-zeros.

Source

pub fn get(&self, r: usize, c: usize) -> f64

Look up the stored value at (r, c), or 0.0 if not present.

Source

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

y = A x.

§Panics

Panics if x.len() != self.ncols().

Source

pub fn scaled_identity_minus_scaled(&self, diag: f64) -> CsrMatrix

Build the Newton matrix A = I − diag·self directly in CSR storage, merging the unit diagonal with the scaled Jacobian entries per row (both in ascending column order) without ever densifying.

Source

pub fn jacobian<F>( f: F, t: f64, y: &[f64], f0: &[f64], cols: Option<&[usize]>, ) -> Result<CsrMatrix, OdeError>
where F: Fn(f64, &[f64], &mut [f64]) -> Result<(), OdeError>,

Build the full Jacobian J = df/dy at (t, y) via forward finite differences, returned as a CsrMatrix. f0 must be f(t, y) and cols is the set of columns to perturb (a sparsity pattern, or None for the full dense pattern). When cols is None every column is finite- differenced, matching the dense linalg::jacobian helper but in compressed storage (exact-zero entries are dropped).

§Errors

Propagates any error returned by the RHS f.

Source

pub fn sparse_solve(&self, b: &[f64]) -> Option<Vec<f64>>

Solve A x = b via sparse LU with partial pivoting.

Returns None if the matrix is (numerically) singular or the dimensions mismatch.

Source§

impl CsrMatrix

Source

pub fn jacobian_colored<F>( f: F, t: f64, y: &[f64], f0: &[f64], pattern: &JacobianPattern, ) -> Result<CsrMatrix, OdeError>
where F: Fn(f64, &[f64], &mut [f64]) -> Result<(), OdeError>,

Jacobian J = df/dy by forward differences, with one RHS call per color instead of one per column.

Columns are grouped with JacobianPattern::column_coloring. All columns of a color are perturbed together, and each row’s entry is recovered from the single column of that color that the row’s pattern contains. The result equals CsrMatrix::jacobian when pattern covers the true structure.

§Errors

Propagates any error returned by the RHS f, or returns OdeError::Invalid if the pattern size does not match y.

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

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> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

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

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

Source§

fn vzip(self) -> V