sparse_transpose.cpp
Go to the documentation of this file.
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 
36 int 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 
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  {
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 
Eigen::SparseMatrix< Scalar >
MtlSparse
mtl::compressed2D< Scalar, mtl::matrix::parameters< mtl::tag::col_major > > MtlSparse
Definition: BenchSparseUtil.h:86
SIZE
#define SIZE
Definition: sparse_transpose.cpp:7
eiToDense
void eiToDense(const EigenSparseMatrix &src, DenseMatrix &dst)
Definition: BenchSparseUtil.h:62
fillMatrix
void fillMatrix(float density, int rows, int cols, EigenSparseMatrix &dst)
Definition: BenchSparseUtil.h:27
timer
static BenchTimer timer
Definition: benchmark-blocking-sizes.cpp:31
MINDENSITY
#define MINDENSITY
Definition: sparse_transpose.cpp:21
BENCH
#define BENCH(X)
Definition: sparse_transpose.cpp:28
trans
static char trans
Definition: blas_interface.hh:58
m1
Matrix3d m1
Definition: IOFormat.cpp:2
copy
int EIGEN_BLAS_FUNC() copy(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:29
eiToMtl
void eiToMtl(const EigenSparseMatrix &src, MtlSparse &dst)
Definition: BenchSparseUtil.h:88
REPEAT
#define REPEAT
Definition: sparse_transpose.cpp:15
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
Eigen::BenchTimer::value
double value(int TIMER=CPU_TIMER) const
Definition: BenchTimer.h:104
GmmDynSparse
gmm::col_matrix< gmm::wsvector< Scalar > > GmmDynSparse
Definition: BenchSparseUtil.h:73
Eigen::BenchTimer
Definition: BenchTimer.h:59
density
Definition: testGaussianConditional.cpp:127
DENSITY
#define DENSITY
Definition: sparse_transpose.cpp:11
GmmSparse
gmm::csc_matrix< Scalar > GmmSparse
Definition: BenchSparseUtil.h:72
DenseMatrix
Matrix< Scalar, Dynamic, Dynamic > DenseMatrix
Definition: BenchSparseUtil.h:23
main
int main(int argc, char *argv[])
Definition: sparse_transpose.cpp:36
gtsam.examples.DogLegOptimizerExample.float
float
Definition: DogLegOptimizerExample.py:113
eiToGmm
void eiToGmm(const EigenSparseMatrix &src, GmmSparse &dst)
Definition: BenchSparseUtil.h:74
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
BenchSparseUtil.h


gtsam
Author(s):
autogenerated on Thu Jun 13 2024 03:05:38