1 use na::{DMatrix, DVector, FullPivLU};
2 
3 // Without unpack.
full_piv_lu_decompose_10x10(bh: &mut criterion::Criterion)4 fn full_piv_lu_decompose_10x10(bh: &mut criterion::Criterion) {
5     let m = DMatrix::<f64>::new_random(10, 10);
6     bh.bench_function("full_piv_lu_decompose_10x10", move |bh| {
7         bh.iter(|| std::hint::black_box(FullPivLU::new(m.clone())))
8     });
9 }
10 
full_piv_lu_decompose_100x100(bh: &mut criterion::Criterion)11 fn full_piv_lu_decompose_100x100(bh: &mut criterion::Criterion) {
12     let m = DMatrix::<f64>::new_random(100, 100);
13     bh.bench_function("full_piv_lu_decompose_100x100", move |bh| {
14         bh.iter(|| std::hint::black_box(FullPivLU::new(m.clone())))
15     });
16 }
17 
full_piv_lu_decompose_500x500(bh: &mut criterion::Criterion)18 fn full_piv_lu_decompose_500x500(bh: &mut criterion::Criterion) {
19     let m = DMatrix::<f64>::new_random(500, 500);
20     bh.bench_function("full_piv_lu_decompose_500x500", move |bh| {
21         bh.iter(|| std::hint::black_box(FullPivLU::new(m.clone())))
22     });
23 }
24 
full_piv_lu_solve_10x10(bh: &mut criterion::Criterion)25 fn full_piv_lu_solve_10x10(bh: &mut criterion::Criterion) {
26     let m = DMatrix::<f64>::new_random(10, 10);
27     let lu = FullPivLU::new(m.clone());
28 
29     bh.bench_function("full_piv_lu_solve_10x10", move |bh| {
30         bh.iter(|| {
31             let mut b = DVector::<f64>::from_element(10, 1.0);
32             lu.solve(&mut b);
33         })
34     });
35 }
36 
full_piv_lu_solve_100x100(bh: &mut criterion::Criterion)37 fn full_piv_lu_solve_100x100(bh: &mut criterion::Criterion) {
38     let m = DMatrix::<f64>::new_random(100, 100);
39     let lu = FullPivLU::new(m.clone());
40 
41     bh.bench_function("full_piv_lu_solve_100x100", move |bh| {
42         bh.iter(|| {
43             let mut b = DVector::<f64>::from_element(100, 1.0);
44             lu.solve(&mut b);
45         })
46     });
47 }
48 
full_piv_lu_solve_500x500(bh: &mut criterion::Criterion)49 fn full_piv_lu_solve_500x500(bh: &mut criterion::Criterion) {
50     let m = DMatrix::<f64>::new_random(500, 500);
51     let lu = FullPivLU::new(m.clone());
52 
53     bh.bench_function("full_piv_lu_solve_500x500", move |bh| {
54         bh.iter(|| {
55             let mut b = DVector::<f64>::from_element(500, 1.0);
56             lu.solve(&mut b);
57         })
58     });
59 }
60 
full_piv_lu_inverse_10x10(bh: &mut criterion::Criterion)61 fn full_piv_lu_inverse_10x10(bh: &mut criterion::Criterion) {
62     let m = DMatrix::<f64>::new_random(10, 10);
63     let lu = FullPivLU::new(m.clone());
64 
65     bh.bench_function("full_piv_lu_inverse_10x10", move |bh| {
66         bh.iter(|| std::hint::black_box(lu.try_inverse()))
67     });
68 }
69 
full_piv_lu_inverse_100x100(bh: &mut criterion::Criterion)70 fn full_piv_lu_inverse_100x100(bh: &mut criterion::Criterion) {
71     let m = DMatrix::<f64>::new_random(100, 100);
72     let lu = FullPivLU::new(m.clone());
73 
74     bh.bench_function("full_piv_lu_inverse_100x100", move |bh| {
75         bh.iter(|| std::hint::black_box(lu.try_inverse()))
76     });
77 }
78 
full_piv_lu_inverse_500x500(bh: &mut criterion::Criterion)79 fn full_piv_lu_inverse_500x500(bh: &mut criterion::Criterion) {
80     let m = DMatrix::<f64>::new_random(500, 500);
81     let lu = FullPivLU::new(m.clone());
82 
83     bh.bench_function("full_piv_lu_inverse_500x500", move |bh| {
84         bh.iter(|| std::hint::black_box(lu.try_inverse()))
85     });
86 }
87 
full_piv_lu_determinant_10x10(bh: &mut criterion::Criterion)88 fn full_piv_lu_determinant_10x10(bh: &mut criterion::Criterion) {
89     let m = DMatrix::<f64>::new_random(10, 10);
90     let lu = FullPivLU::new(m.clone());
91 
92     bh.bench_function("full_piv_lu_determinant_10x10", move |bh| {
93         bh.iter(|| std::hint::black_box(lu.determinant()))
94     });
95 }
96 
full_piv_lu_determinant_100x100(bh: &mut criterion::Criterion)97 fn full_piv_lu_determinant_100x100(bh: &mut criterion::Criterion) {
98     let m = DMatrix::<f64>::new_random(100, 100);
99     let lu = FullPivLU::new(m.clone());
100 
101     bh.bench_function("full_piv_lu_determinant_100x100", move |bh| {
102         bh.iter(|| std::hint::black_box(lu.determinant()))
103     });
104 }
105 
full_piv_lu_determinant_500x500(bh: &mut criterion::Criterion)106 fn full_piv_lu_determinant_500x500(bh: &mut criterion::Criterion) {
107     let m = DMatrix::<f64>::new_random(500, 500);
108     let lu = FullPivLU::new(m.clone());
109 
110     bh.bench_function("full_piv_lu_determinant_500x500", move |bh| {
111         bh.iter(|| std::hint::black_box(lu.determinant()))
112     });
113 }
114 
115 criterion_group!(
116     full_piv_lu,
117     full_piv_lu_decompose_10x10,
118     full_piv_lu_decompose_100x100,
119     //    full_piv_lu_decompose_500x500,
120     full_piv_lu_solve_10x10,
121     full_piv_lu_solve_100x100,
122     //    full_piv_lu_solve_500x500,
123     full_piv_lu_inverse_10x10,
124     full_piv_lu_inverse_100x100,
125     //    full_piv_lu_inverse_500x500,
126     full_piv_lu_determinant_10x10,
127     full_piv_lu_determinant_100x100,
128     //    full_piv_lu_determinant_500x500
129 );
130