bench_svd.cpp
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2013 Gauthier Brun <brun.gauthier@gmail.com>
00005 // Copyright (C) 2013 Nicolas Carre <nicolas.carre@ensimag.fr>
00006 // Copyright (C) 2013 Jean Ceccato <jean.ceccato@ensimag.fr>
00007 // Copyright (C) 2013 Pierre Zoppitelli <pierre.zoppitelli@ensimag.fr>
00008 //
00009 // This Source Code Form is subject to the terms of the Mozilla
00010 // Public License v. 2.0. If a copy of the MPL was not distributed
00011 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/
00012 
00013 // Bench to compare the efficiency of SVD algorithms
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 // number of computations of each algorithm before the print of the time
00024 #ifndef REPEAT
00025 #define REPEAT 10
00026 #endif
00027 
00028 // number of tests of the same type
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   //std::cout<<"On a (Dynamic, Dynamic) (128, 128) Matrix" <<std::endl;
00116   //bench_svd<Matrix<double,Dynamic,Dynamic> >(Matrix<double,Dynamic,Dynamic>(128, 128));
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 }


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:29:12