sparse_transpose.cpp File Reference
#include "BenchSparseUtil.h"

Macros

#define SIZE   10000
 
#define DENSITY   0.01
 
#define REPEAT   1
 
#define MINDENSITY   0.0004
 
#define NBTRIES   10
 
#define BENCH(X)
 

Functions

int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ BENCH

#define BENCH (   X)
Value:
timer.reset(); \
for (int _j = 0; _j < NBTRIES; ++_j) { \
timer.start(); \
for (int _k = 0; _k < REPEAT; ++_k) { \
X \
} \
timer.stop(); \
}
#define REPEAT
Definition: sparse_transpose.cpp:17
#define NBTRIES
Definition: sparse_transpose.cpp:27

◆ DENSITY

#define DENSITY   0.01

◆ MINDENSITY

#define MINDENSITY   0.0004

◆ NBTRIES

#define NBTRIES   10

◆ REPEAT

#define REPEAT   1

◆ SIZE

#define SIZE   10000

Function Documentation

◆ main()

int main ( int argc  ,
char argv[] 
)
40  {
41  int rows = SIZE;
42  int cols = SIZE;
43  float density = DENSITY;
44 
45  EigenSparseMatrix sm1(rows, cols), sm3(rows, cols);
46 
48  for (float density = DENSITY; density >= MINDENSITY; density *= 0.5) {
49  fillMatrix(density, rows, cols, sm1);
50 
51 // dense matrices
52 #ifdef DENSEMATRIX
53  {
54  DenseMatrix m1(rows, cols), m3(rows, cols);
55  eiToDense(sm1, m1);
56  BENCH(for (int k = 0; k < REPEAT; ++k) m3 = m1.transpose();)
57  std::cout << " Eigen dense:\t" << timer.value() << endl;
58  }
59 #endif
60 
61  std::cout << "Non zeros: " << sm1.nonZeros() / float(sm1.rows() * sm1.cols()) * 100 << "%\n";
62 
63  // eigen sparse matrices
64  {
65  BENCH(for (int k = 0; k < REPEAT; ++k) sm3 = sm1.transpose();)
66  std::cout << " Eigen:\t" << timer.value() << endl;
67  }
68 
69 // CSparse
70 #ifdef CSPARSE
71  {
72  cs *m1, *m3;
73  eiToCSparse(sm1, m1);
74 
75  BENCH(for (int k = 0; k < REPEAT; ++k) {
76  m3 = cs_transpose(m1, 1);
77  cs_spfree(m3);
78  })
79  std::cout << " CSparse:\t" << timer.value() << endl;
80  }
81 #endif
82 
83 // GMM++
84 #ifndef NOGMM
85  {
86  GmmDynSparse gmmT3(rows, cols);
87  GmmSparse m1(rows, cols), m3(rows, cols);
88  eiToGmm(sm1, m1);
89  BENCH(for (int k = 0; k < REPEAT; ++k) gmm::copy(gmm::transposed(m1), m3);)
90  std::cout << " GMM:\t\t" << timer.value() << endl;
91  }
92 #endif
93 
94 // MTL4
95 #ifndef NOMTL
96  {
97  MtlSparse m1(rows, cols), m3(rows, cols);
98  eiToMtl(sm1, m1);
99  BENCH(for (int k = 0; k < REPEAT; ++k) m3 = trans(m1);)
100  std::cout << " MTL4:\t\t" << timer.value() << endl;
101  }
102 #endif
103 
104  std::cout << "\n\n";
105  }
106 
107  return 0;
108 }
void eiToGmm(const EigenSparseMatrix &src, GmmSparse &dst)
Definition: BenchSparseUtil.h:64
void eiToDense(const EigenSparseMatrix &src, DenseMatrix &dst)
Definition: BenchSparseUtil.h:54
void fillMatrix(float density, int rows, int cols, EigenSparseMatrix &dst)
Definition: BenchSparseUtil.h:27
gmm::col_matrix< gmm::wsvector< Scalar > > GmmDynSparse
Definition: BenchSparseUtil.h:63
mtl::compressed2D< Scalar, mtl::matrix::parameters< mtl::tag::col_major > > MtlSparse
Definition: BenchSparseUtil.h:74
gmm::csc_matrix< Scalar > GmmSparse
Definition: BenchSparseUtil.h:62
void eiToMtl(const EigenSparseMatrix &src, MtlSparse &dst)
Definition: BenchSparseUtil.h:76
Matrix3d m1
Definition: IOFormat.cpp:2
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
Definition: BenchTimer.h:55
EIGEN_BLAS_FUNC() copy(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:32
char * trans
Definition: level2_impl.h:240
char char char int int * k
Definition: level2_impl.h:374
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
squared absolute value
Definition: GlobalFunctions.h:87
density
Definition: UniformPSDSelfTest.py:19
t
Definition: plotPSD.py:36
double timer
Definition: oomph_metis_from_parmetis_3.1.1/struct.h:210
#define MINDENSITY
Definition: sparse_transpose.cpp:23
#define BENCH(X)
Definition: sparse_transpose.cpp:30
#define SIZE
Definition: sparse_transpose.cpp:9
#define DENSITY
Definition: sparse_transpose.cpp:13

References BENCH, cols, copy(), UniformPSDSelfTest::density, DENSITY, eiToDense(), eiToGmm(), eiToMtl(), fillMatrix(), k, m1, MINDENSITY, REPEAT, rows, SIZE, trans, and Eigen::SparseMatrixBase< Derived >::transpose().