Skip to main content

05_lapack_decompositions/
05_lapack_decompositions.rs

1use apple_accelerate::{lu_decompose_f32, solve_linear_system_f32};
2
3fn main() {
4    // Column-major 2x2 matrix [[3, 1], [1, 2]].
5    let matrix = [3.0_f32, 1.0, 1.0, 2.0];
6    let lu = lu_decompose_f32(&matrix, 2).expect("lu");
7    assert_eq!(lu.dimension(), 2);
8    assert_eq!(lu.factors().len(), 4);
9
10    let solution = solve_linear_system_f32(&matrix, 2, &[9.0_f32, 8.0]).expect("solve");
11    assert!((solution[0] - 2.0).abs() < 1.0e-5);
12    assert!((solution[1] - 3.0).abs() < 1.0e-5);
13
14    println!(
15        "lapack smoke passed: pivots={:?} solution={solution:?}",
16        lu.pivots()
17    );
18}