bench_svd.cpp File Reference
#include <iostream>
#include <bench/BenchTimer.h>
#include <unsupported/Eigen/SVD>

Macros

#define REPEAT   10
 
#define NUMBER_SAMPLE   2
 

Functions

template<typename MatrixType >
void bench_svd (const MatrixType &a=MatrixType())
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ NUMBER_SAMPLE

#define NUMBER_SAMPLE   2

◆ REPEAT

#define REPEAT   10

Function Documentation

◆ bench_svd()

template<typename MatrixType >
void bench_svd ( const MatrixType a = MatrixType())
33  {
34  MatrixType m = MatrixType::Random(a.rows(), a.cols());
35  BenchTimer timerJacobi;
36  BenchTimer timerBDC;
37  timerJacobi.reset();
38  timerBDC.reset();
39 
40  cout << " Only compute Singular Values" << endl;
41  for (int k = 1; k <= NUMBER_SAMPLE; ++k) {
42  timerBDC.start();
43  for (int i = 0; i < REPEAT; ++i) {
44  BDCSVD<MatrixType> bdc_matrix(m);
45  }
46  timerBDC.stop();
47 
48  timerJacobi.start();
49  for (int i = 0; i < REPEAT; ++i) {
50  JacobiSVD<MatrixType> jacobi_matrix(m);
51  }
52  timerJacobi.stop();
53 
54  cout << "Sample " << k << " : " << REPEAT << " computations : Jacobi : " << fixed << timerJacobi.value() << "s ";
55  cout << " || "
56  << " BDC : " << timerBDC.value() << "s " << endl
57  << endl;
58 
59  if (timerBDC.value() >= timerJacobi.value())
60  cout << "KO : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" << endl;
61  else
62  cout << "OK : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" << endl;
63  }
64  cout << " =================" << endl;
65  std::cout << std::endl;
66  timerJacobi.reset();
67  timerBDC.reset();
68  cout << " Computes rotation matrix" << endl;
69  for (int k = 1; k <= NUMBER_SAMPLE; ++k) {
70  timerBDC.start();
71  for (int i = 0; i < REPEAT; ++i) {
73  }
74  timerBDC.stop();
75 
76  timerJacobi.start();
77  for (int i = 0; i < REPEAT; ++i) {
79  }
80  timerJacobi.stop();
81 
82  cout << "Sample " << k << " : " << REPEAT << " computations : Jacobi : " << fixed << timerJacobi.value() << "s ";
83  cout << " || "
84  << " BDC : " << timerBDC.value() << "s " << endl
85  << endl;
86 
87  if (timerBDC.value() >= timerJacobi.value())
88  cout << "KO : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" << endl;
89  else
90  cout << "OK : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" << endl;
91  }
92  std::cout << std::endl;
93 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define REPEAT
Definition: bench_svd.cpp:24
#define NUMBER_SAMPLE
Definition: bench_svd.cpp:29
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
class Bidiagonal Divide and Conquer SVD
Definition: BDCSVD.h:85
Definition: BenchTimer.h:55
double value(int TIMER=CPU_TIMER) const
Definition: BenchTimer.h:94
void reset()
Definition: BenchTimer.h:68
void stop()
Definition: BenchTimer.h:77
void start()
Definition: BenchTimer.h:73
Two-sided Jacobi SVD decomposition of a rectangular matrix.
Definition: JacobiSVD.h:500
@ ComputeFullV
Definition: Constants.h:393
@ ComputeFullU
Definition: Constants.h:389
const Scalar * a
Definition: level2_cplx_impl.h:32
int * m
Definition: level2_cplx_impl.h:294
char char char int int * k
Definition: level2_impl.h:374

References a, Eigen::ComputeFullU, Eigen::ComputeFullV, i, k, m, NUMBER_SAMPLE, REPEAT, Eigen::BenchTimer::reset(), Eigen::BenchTimer::start(), Eigen::BenchTimer::stop(), and Eigen::BenchTimer::value().

◆ main()

int main ( int argc  ,
char argv[] 
)
95  {
96  std::cout << std::endl;
97 
98  std::cout << "On a (Dynamic, Dynamic) (6, 6) Matrix" << std::endl;
99  bench_svd<Matrix<double, Dynamic, Dynamic> >(Matrix<double, Dynamic, Dynamic>(6, 6));
100 
101  std::cout << "On a (Dynamic, Dynamic) (32, 32) Matrix" << std::endl;
102  bench_svd<Matrix<double, Dynamic, Dynamic> >(Matrix<double, Dynamic, Dynamic>(32, 32));
103 
104  // std::cout<<"On a (Dynamic, Dynamic) (128, 128) Matrix" <<std::endl;
105  // bench_svd<Matrix<double,Dynamic,Dynamic> >(Matrix<double,Dynamic,Dynamic>(128, 128));
106 
107  std::cout << "On a (Dynamic, Dynamic) (160, 160) Matrix" << std::endl;
108  bench_svd<Matrix<double, Dynamic, Dynamic> >(Matrix<double, Dynamic, Dynamic>(160, 160));
109 
110  std::cout << "--------------------------------------------------------------------" << std::endl;
111 }