Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <iostream>
00016 #include <bench/BenchTimer.h>
00017 #include <unsupported/Eigen/SVD>
00018
00019
00020 using namespace Eigen;
00021 using namespace std;
00022
00023
00024 #ifndef REPEAT
00025 #define REPEAT 10
00026 #endif
00027
00028
00029 #ifndef NUMBER_SAMPLE
00030 #define NUMBER_SAMPLE 2
00031 #endif
00032
00033 template<typename MatrixType>
00034 void bench_svd(const MatrixType& a = MatrixType())
00035 {
00036 MatrixType m = MatrixType::Random(a.rows(), a.cols());
00037 BenchTimer timerJacobi;
00038 BenchTimer timerBDC;
00039 timerJacobi.reset();
00040 timerBDC.reset();
00041
00042 cout << " Only compute Singular Values" <<endl;
00043 for (int k=1; k<=NUMBER_SAMPLE; ++k)
00044 {
00045 timerBDC.start();
00046 for (int i=0; i<REPEAT; ++i)
00047 {
00048 BDCSVD<MatrixType> bdc_matrix(m);
00049 }
00050 timerBDC.stop();
00051
00052 timerJacobi.start();
00053 for (int i=0; i<REPEAT; ++i)
00054 {
00055 JacobiSVD<MatrixType> jacobi_matrix(m);
00056 }
00057 timerJacobi.stop();
00058
00059
00060 cout << "Sample " << k << " : " << REPEAT << " computations : Jacobi : " << fixed << timerJacobi.value() << "s ";
00061 cout << " || " << " BDC : " << timerBDC.value() << "s " <<endl <<endl;
00062
00063 if (timerBDC.value() >= timerJacobi.value())
00064 cout << "KO : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" <<endl;
00065 else
00066 cout << "OK : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" <<endl;
00067
00068 }
00069 cout << " =================" <<endl;
00070 std::cout<< std::endl;
00071 timerJacobi.reset();
00072 timerBDC.reset();
00073 cout << " Computes rotaion matrix" <<endl;
00074 for (int k=1; k<=NUMBER_SAMPLE; ++k)
00075 {
00076 timerBDC.start();
00077 for (int i=0; i<REPEAT; ++i)
00078 {
00079 BDCSVD<MatrixType> bdc_matrix(m, ComputeFullU|ComputeFullV);
00080 }
00081 timerBDC.stop();
00082
00083 timerJacobi.start();
00084 for (int i=0; i<REPEAT; ++i)
00085 {
00086 JacobiSVD<MatrixType> jacobi_matrix(m, ComputeFullU|ComputeFullV);
00087 }
00088 timerJacobi.stop();
00089
00090
00091 cout << "Sample " << k << " : " << REPEAT << " computations : Jacobi : " << fixed << timerJacobi.value() << "s ";
00092 cout << " || " << " BDC : " << timerBDC.value() << "s " <<endl <<endl;
00093
00094 if (timerBDC.value() >= timerJacobi.value())
00095 cout << "KO : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" <<endl;
00096 else
00097 cout << "OK : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" <<endl;
00098
00099 }
00100 std::cout<< std::endl;
00101 }
00102
00103
00104
00105 int main(int argc, char* argv[])
00106 {
00107 std::cout<< std::endl;
00108
00109 std::cout<<"On a (Dynamic, Dynamic) (6, 6) Matrix" <<std::endl;
00110 bench_svd<Matrix<double,Dynamic,Dynamic> >(Matrix<double,Dynamic,Dynamic>(6, 6));
00111
00112 std::cout<<"On a (Dynamic, Dynamic) (32, 32) Matrix" <<std::endl;
00113 bench_svd<Matrix<double,Dynamic,Dynamic> >(Matrix<double,Dynamic,Dynamic>(32, 32));
00114
00115
00116
00117
00118 std::cout<<"On a (Dynamic, Dynamic) (160, 160) Matrix" <<std::endl;
00119 bench_svd<Matrix<double,Dynamic,Dynamic> >(Matrix<double,Dynamic,Dynamic>(160, 160));
00120
00121 std::cout<< "--------------------------------------------------------------------"<< std::endl;
00122
00123 }