Skip to main content

tridiagonal_solve

Function tridiagonal_solve 

Source
pub fn tridiagonal_solve<B: Backend, T: LinalgScalar>(
    dl: &Array<B, T>,
    d: &Array<B, T>,
    du: &Array<B, T>,
    b: &Array<B, T>,
    perturb_singular: bool,
) -> Array<B, T>
Expand description

The solution x of A x = b for each tridiagonal matrix A, as lax.linalg.tridiagonal_solve: dl[..., i] = A[i, i - 1] (dl[..., 0] is ignored), d[..., i] = A[i, i], and du[..., i] = A[i, i + 1] (du[..., m - 1] is ignored), each [..., m], and b is [..., m, n]. Gaussian elimination with partial pivoting (LAPACK’s gtsv): singular systems give NaNs, unless perturb_singular, which perturbs tiny pivots so that numerically singular systems (as in inverse iteration) give finite solutions. Differentiable in all inputs.

§Examples

use ruxla_core::{Array, Native, lax::linalg::tridiagonal_solve};

// [[2, 1, 0], [1, 2, 1], [0, 1, 2]] x = [4, 8, 8]
let dl = Array::<Native, f64>::from_vec(vec![0.0, 1.0, 1.0], [3]);
let d = Array::<Native, f64>::from_vec(vec![2.0, 2.0, 2.0], [3]);
let du = Array::<Native, f64>::from_vec(vec![1.0, 1.0, 0.0], [3]);
let b = Array::<Native, f64>::from_vec(vec![4.0, 8.0, 8.0], [3, 1]);
let x = tridiagonal_solve(&dl, &d, &du, &b, false);
let x = x.to_vec();
for (got, expected) in x.iter().zip([1.0, 2.0, 3.0]) {
    assert!((got - expected).abs() < 1e-12);
}

§Panics

Panics if the shapes do not match.