sprs/sparse/
linalg.rs

1//! Sparse linear algebra
2//!
3//! This module contains solvers for sparse linear systems. Currently
4//! there are solver for sparse triangular systems and symmetric systems.
5
6use crate::{DenseVector, DenseVectorMut};
7use num_traits::Num;
8
9pub mod bicgstab;
10pub mod etree;
11pub mod ordering;
12pub mod trisolve;
13
14pub use self::ordering::reverse_cuthill_mckee;
15
16/// Diagonal solve
17pub fn diag_solve<'a, N, V1, V2>(diag: V1, mut x: V2)
18where
19    N: 'a + Clone + Num + std::ops::DivAssign,
20    for<'r> N: std::ops::DivAssign<&'r N>,
21    V1: DenseVector<Scalar = N>,
22    V2: DenseVectorMut + DenseVector<Scalar = N>,
23{
24    let n = x.dim();
25    assert_eq!(diag.dim(), n);
26    for i in 0..n {
27        *x.index_mut(i) /= diag.index(i);
28    }
29}