lsmr

Function lsmr 

Source
pub fn lsmr<T, S>(
    matrix: &S,
    b: &ArrayView1<'_, T>,
    x0: Option<&ArrayView1<'_, T>>,
    options: LSMROptions,
) -> SparseResult<LSMRResult<T>>
where T: Float + SparseElement + Debug + Copy + 'static, S: SparseArray<T>,
Expand description

LSMR algorithm for sparse least squares problems

Solves the least squares problem min ||Ax - b||_2 or the linear system Ax = b. The method is based on the Golub-Kahan bidiagonalization process.

§Arguments

  • matrix - The coefficient matrix A (m x n)
  • b - The right-hand side vector (length m)
  • x0 - Initial guess (optional, length n)
  • options - Solver options

§Returns

An LSMRResult containing the solution and convergence information

§Example

use scirs2_sparse::csr_array::CsrArray;
use scirs2_sparse::linalg::{lsmr, LSMROptions};
use scirs2_core::ndarray::Array1;

// Create an overdetermined system
let rows = vec![0, 0, 1, 1, 2, 2];
let cols = vec![0, 1, 0, 1, 0, 1];
let data = vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0];
let matrix = CsrArray::from_triplets(&rows, &cols, &data, (3, 2), false).unwrap();

// Right-hand side
let b = Array1::from_vec(vec![1.0, 2.0, 3.0]);

// Solve using LSMR
let result = lsmr(&matrix, &b.view(), None, LSMROptions::default()).unwrap();