Debian Codegraph @

debian/missing-sources/nalgebra/benches/linalg/svd.rs

raw
1 use na::{Matrix2, Matrix3, Matrix4, SVD};
2
3 fn svd_decompose_2x2_f32(bh: &mut criterion::Criterion) {
4 let m = Matrix2::<f32>::new_random();
5 bh.bench_function("svd_decompose_2x2", move |bh| {
6 bh.iter(|| std::hint::black_box(SVD::new_unordered(m.clone(), true, true)))
7 });
8 }
9
10 fn svd_decompose_3x3_f32(bh: &mut criterion::Criterion) {
11 let m = Matrix3::<f32>::new_random();
12 bh.bench_function("svd_decompose_3x3", move |bh| {
13 bh.iter(|| std::hint::black_box(SVD::new_unordered(m.clone(), true, true)))
14 });
15 }
16
17 fn svd_decompose_4x4(bh: &mut criterion::Criterion) {
18 let m = Matrix4::<f64>::new_random();
19 bh.bench_function("svd_decompose_4x4", move |bh| {
20 bh.iter(|| std::hint::black_box(SVD::new(m.clone(), true, true)))
21 });
22 }
23
24 fn svd_decompose_10x10(bh: &mut criterion::Criterion) {
25 let m = crate::reproducible_dmatrix(10, 10);
26 bh.bench_function("svd_decompose_10x10", move |bh| {
27 bh.iter(|| std::hint::black_box(SVD::new(m.clone(), true, true)))
28 });
29 }
30
31 fn svd_decompose_100x100(bh: &mut criterion::Criterion) {
32 let m = crate::reproducible_dmatrix(100, 100);
33 bh.bench_function("svd_decompose_100x100", move |bh| {
34 bh.iter(|| std::hint::black_box(SVD::new(m.clone(), true, true)))
35 });
36 }
37
38 fn svd_decompose_200x200(bh: &mut criterion::Criterion) {
39 let m = crate::reproducible_dmatrix(200, 200);
40 bh.bench_function("svd_decompose_200x200", move |bh| {
41 bh.iter(|| std::hint::black_box(SVD::new(m.clone(), true, true)))
42 });
43 }
44
45 fn rank_4x4(bh: &mut criterion::Criterion) {
46 let m = Matrix4::<f64>::new_random();
47 bh.bench_function("rank_4x4", move |bh| {
48 bh.iter(|| std::hint::black_box(m.rank(1.0e-10)))
49 });
50 }
51
52 fn rank_10x10(bh: &mut criterion::Criterion) {
53 let m = crate::reproducible_dmatrix(10, 10);
54 bh.bench_function("rank_10x10", move |bh| {
55 bh.iter(|| std::hint::black_box(m.rank(1.0e-10)))
56 });
57 }
58
59 fn rank_100x100(bh: &mut criterion::Criterion) {
60 let m = crate::reproducible_dmatrix(100, 100);
61 bh.bench_function("rank_100x100", move |bh| {
62 bh.iter(|| std::hint::black_box(m.rank(1.0e-10)))
63 });
64 }
65
66 fn rank_200x200(bh: &mut criterion::Criterion) {
67 let m = crate::reproducible_dmatrix(200, 200);
68 bh.bench_function("rank_200x200", move |bh| {
69 bh.iter(|| std::hint::black_box(m.rank(1.0e-10)))
70 });
71 }
72
73 fn singular_values_4x4(bh: &mut criterion::Criterion) {
74 let m = Matrix4::<f64>::new_random();
75 bh.bench_function("singular_values_4x4", move |bh| {
76 bh.iter(|| std::hint::black_box(m.singular_values()))
77 });
78 }
79
80 fn singular_values_10x10(bh: &mut criterion::Criterion) {
81 let m = crate::reproducible_dmatrix(10, 10);
82 bh.bench_function("singular_values_10x10", move |bh| {
83 bh.iter(|| std::hint::black_box(m.singular_values()))
84 });
85 }
86
87 fn singular_values_100x100(bh: &mut criterion::Criterion) {
88 let m = crate::reproducible_dmatrix(100, 100);
89 bh.bench_function("singular_values_100x100", move |bh| {
90 bh.iter(|| std::hint::black_box(m.singular_values()))
91 });
92 }
93
94 fn singular_values_200x200(bh: &mut criterion::Criterion) {
95 let m = crate::reproducible_dmatrix(200, 200);
96 bh.bench_function("singular_values_200x200", move |bh| {
97 bh.iter(|| std::hint::black_box(m.singular_values()))
98 });
99 }
100
101 fn pseudo_inverse_4x4(bh: &mut criterion::Criterion) {
102 let m = Matrix4::<f64>::new_random();
103 bh.bench_function("pseudo_inverse_4x4", move |bh| {
104 bh.iter(|| std::hint::black_box(m.clone().pseudo_inverse(1.0e-10)))
105 });
106 }
107
108 fn pseudo_inverse_10x10(bh: &mut criterion::Criterion) {
109 let m = crate::reproducible_dmatrix(10, 10);
110 bh.bench_function("pseudo_inverse_10x10", move |bh| {
111 bh.iter(|| std::hint::black_box(m.clone().pseudo_inverse(1.0e-10)))
112 });
113 }
114
115 fn pseudo_inverse_100x100(bh: &mut criterion::Criterion) {
116 let m = crate::reproducible_dmatrix(100, 100);
117 bh.bench_function("pseudo_inverse_100x100", move |bh| {
118 bh.iter(|| std::hint::black_box(m.clone().pseudo_inverse(1.0e-10)))
119 });
120 }
121
122 fn pseudo_inverse_200x200(bh: &mut criterion::Criterion) {
123 let m = crate::reproducible_dmatrix(200, 200);
124 bh.bench_function("pseudo_inverse_200x200", move |bh| {
125 bh.iter(|| std::hint::black_box(m.clone().pseudo_inverse(1.0e-10)))
126 });
127 }
128
129 criterion_group!(
130 svd,
131 svd_decompose_2x2_f32,
132 svd_decompose_3x3_f32,
133 svd_decompose_4x4,
134 svd_decompose_10x10,
135 svd_decompose_100x100,
136 svd_decompose_200x200,
137 rank_4x4,
138 rank_10x10,
139 rank_100x100,
140 rank_200x200,
141 singular_values_4x4,
142 singular_values_10x10,
143 singular_values_100x100,
144 singular_values_200x200,
145 pseudo_inverse_4x4,
146 pseudo_inverse_10x10,
147 pseudo_inverse_100x100,
148 pseudo_inverse_200x200
149 );