#sparse #math #faer #gmres

faer_gmres

GMRES implementation using faer

3 releases

0.0.3 Apr 15, 2024
0.0.2 Apr 4, 2024
0.0.1 Mar 18, 2024

#436 in Algorithms

Download history 122/week @ 2024-03-18 167/week @ 2024-04-01 9/week @ 2024-04-08 157/week @ 2024-04-15

334 downloads per month

MIT license

23KB
452 lines

About

Crates.io

GMRES in rust using faer.

Solves linear systems of the form: Ax=b, where A is sparse. Depends on faer for sparse matrix implementation and sparse QR solver.

Use

Example use:

use faer_gmres::gmres;
use faer::prelude::*;
use faer::sparse::*;
use faer::mat;

// create faer sparse mat from triplets
let a_test_triplets = vec![
    (0, 0, 1.0),
    (1, 1, 2.0),
    (2, 2, 3.0),
    ];
let a_test = SparseColMat::<usize, f64>::try_new_from_triplets(
    3, 3,
    &a_test_triplets).unwrap();

// rhs
let b = faer::mat![
    [2.0],
    [2.0],
    [2.0],
    ];

// init sol guess
let x0 = faer::mat![
    [0.0],
    [0.0],
    [0.0],
    ];

// the final None arg means do not apply left preconditioning
let (res_x, err, iters) = gmres(a_test.as_ref(), b.as_ref(), x0.as_ref(), 10, 1e-8, None).unwrap();
println!("Result x: {:?}", res_x);
println!("Error x: {:?}", err);
println!("Iters : {:?}", iters);

Preconditioned GMRES:

A preconditioner can be supplied:

// continued from above...
use faer_gmres::{JacobiPreconLinOp, LinOp};
let jacobi_pre = JacobiPreconLinOp::new(a_test.as_ref());
let (res_x, err, iters) = gmres(a_test.as_ref(), b.as_ref(), x0.as_ref(), 10, 1e-8, Some(&jacobi_pre)).unwrap();

Restarted GMRES:

A restarted GMRES routine is provided:

use faer_gmres::restarted_gmres;
let max_inner = 30;
let max_outer = 50;
let (res_x, err, iters) = restarted_gmres(
    a_test.as_ref(), b.as_ref(), x0.as_ref(), max_inner, max_outer, 1e-8, None).unwrap();

This will repeatedly call the inner GMRES routine, using the previous outer iteration's solution as the inital guess for the next outer solve. The current implementation of restarted GMRES in this package can reduce the memory requirements needed, but slow convergence.

TODO

  • Python bindings
  • Additional tests
  • Benchmarks
  • Performance improvements

References and Credits

This package is an adaptation of GMRES implementation by RLando:

License

MIT

Dependencies

~10MB
~221K SLoC