use russell_lab::*; fn main() -> Result<(), StrError> { // data for matrix "A" #[rustfmt::skip] let data = [ [ 3.0, 0.0,-3.0, 0.0], [ 0.0, 3.0, 1.0, 2.0], [-3.0, 1.0, 4.0, 1.0], [ 0.0, 2.0, 1.0, 3.0], ]; // set matrix (lower) let mut a_lower = Matrix::from_lower(&data)?; // set matrix (upper) let mut a_upper = Matrix::from_upper(&data)?; // perform Cholesky factorization (lower) mat_cholesky(&mut a_lower, false)?; let l = &a_lower; // perform Cholesky factorization (upper) mat_cholesky(&mut a_upper, true)?; let u = &a_upper; // check: l ⋅ lᵀ = a let m = l.nrow(); let mut l_lt = Matrix::new(m, m); for i in 0..m { for j in 0..m { for k in 0..m { l_lt.add(i, j, l.get(i, k) * l.get(j, k)); } } } mat_approx_eq(&l_lt, &data, 1e-14); // check: uᵀ ⋅ u = a let m = u.nrow(); let mut ut_u = Matrix::new(m, m); for i in 0..m { for j in 0..m { for k in 0..m { ut_u.add(i, j, u.get(k, i) * u.get(k, j)); } } } mat_approx_eq(&ut_u, &data, 1e-14); Ok(()) }