source: pacpussensors/trunk/Vislab/lib3dv/eigen/bench/sparse_transpose.cpp@ 139

Last change on this file since 139 was 136, checked in by ldecherf, 8 years ago

Doc

File size: 2.3 KB
Line 
1
2//g++ -O3 -g0 -DNDEBUG sparse_transpose.cpp -I.. -I/home/gael/Coding/LinearAlgebra/mtl4/ -DDENSITY=0.005 -DSIZE=10000 && ./a.out
3// -DNOGMM -DNOMTL
4// -DCSPARSE -I /home/gael/Coding/LinearAlgebra/CSparse/Include/ /home/gael/Coding/LinearAlgebra/CSparse/Lib/libcsparse.a
5
6#ifndef SIZE
7#define SIZE 10000
8#endif
9
10#ifndef DENSITY
11#define DENSITY 0.01
12#endif
13
14#ifndef REPEAT
15#define REPEAT 1
16#endif
17
18#include "BenchSparseUtil.h"
19
20#ifndef MINDENSITY
21#define MINDENSITY 0.0004
22#endif
23
24#ifndef NBTRIES
25#define NBTRIES 10
26#endif
27
28#define BENCH(X) \
29 timer.reset(); \
30 for (int _j=0; _j<NBTRIES; ++_j) { \
31 timer.start(); \
32 for (int _k=0; _k<REPEAT; ++_k) { \
33 X \
34 } timer.stop(); }
35
36int main(int argc, char *argv[])
37{
38 int rows = SIZE;
39 int cols = SIZE;
40 float density = DENSITY;
41
42 EigenSparseMatrix sm1(rows,cols), sm3(rows,cols);
43
44 BenchTimer timer;
45 for (float density = DENSITY; density>=MINDENSITY; density*=0.5)
46 {
47 fillMatrix(density, rows, cols, sm1);
48
49 // dense matrices
50 #ifdef DENSEMATRIX
51 {
52 DenseMatrix m1(rows,cols), m3(rows,cols);
53 eiToDense(sm1, m1);
54 BENCH(for (int k=0; k<REPEAT; ++k) m3 = m1.transpose();)
55 std::cout << " Eigen dense:\t" << timer.value() << endl;
56 }
57 #endif
58
59 std::cout << "Non zeros: " << sm1.nonZeros()/float(sm1.rows()*sm1.cols())*100 << "%\n";
60
61 // eigen sparse matrices
62 {
63 BENCH(for (int k=0; k<REPEAT; ++k) sm3 = sm1.transpose();)
64 std::cout << " Eigen:\t" << timer.value() << endl;
65 }
66
67 // CSparse
68 #ifdef CSPARSE
69 {
70 cs *m1, *m3;
71 eiToCSparse(sm1, m1);
72
73 BENCH(for (int k=0; k<REPEAT; ++k) { m3 = cs_transpose(m1,1); cs_spfree(m3);})
74 std::cout << " CSparse:\t" << timer.value() << endl;
75 }
76 #endif
77
78 // GMM++
79 #ifndef NOGMM
80 {
81 GmmDynSparse gmmT3(rows,cols);
82 GmmSparse m1(rows,cols), m3(rows,cols);
83 eiToGmm(sm1, m1);
84 BENCH(for (int k=0; k<REPEAT; ++k) gmm::copy(gmm::transposed(m1),m3);)
85 std::cout << " GMM:\t\t" << timer.value() << endl;
86 }
87 #endif
88
89 // MTL4
90 #ifndef NOMTL
91 {
92 MtlSparse m1(rows,cols), m3(rows,cols);
93 eiToMtl(sm1, m1);
94 BENCH(for (int k=0; k<REPEAT; ++k) m3 = trans(m1);)
95 std::cout << " MTL4:\t\t" << timer.value() << endl;
96 }
97 #endif
98
99 std::cout << "\n\n";
100 }
101
102 return 0;
103}
104
Note: See TracBrowser for help on using the repository browser.