diff options
author | Carlos Hernandez <chernand@google.com> | 2014-08-05 17:53:32 -0700 |
---|---|---|
committer | Carlos Hernandez <chernand@google.com> | 2014-08-05 17:54:05 -0700 |
commit | 7faaa9f3f0df9d23790277834d426c3d992ac3ba (patch) | |
tree | b788ae3b96daf9f5a79d8ec434e1e9edd56b3a72 /unsupported/bench/bench_svd.cpp | |
parent | 810535bb0c575a003b32076e5352ab8fd3f23a1c (diff) | |
download | eigen-7faaa9f3f0df9d23790277834d426c3d992ac3ba.tar.gz |
Update Eigen to the latest stable release, 3.2.2android-wear-5.1.1_r1android-wear-5.1.0_r1android-wear-5.0.0_r1android-l-preview_r2android-cts-5.1_r9android-cts-5.1_r8android-cts-5.1_r7android-cts-5.1_r6android-cts-5.1_r5android-cts-5.1_r4android-cts-5.1_r3android-cts-5.1_r28android-cts-5.1_r27android-cts-5.1_r26android-cts-5.1_r25android-cts-5.1_r24android-cts-5.1_r23android-cts-5.1_r22android-cts-5.1_r21android-cts-5.1_r20android-cts-5.1_r2android-cts-5.1_r19android-cts-5.1_r18android-cts-5.1_r17android-cts-5.1_r16android-cts-5.1_r15android-cts-5.1_r14android-cts-5.1_r13android-cts-5.1_r10android-cts-5.1_r1android-cts-5.0_r9android-cts-5.0_r8android-cts-5.0_r7android-cts-5.0_r6android-cts-5.0_r5android-cts-5.0_r4android-cts-5.0_r3android-5.1.1_r9android-5.1.1_r8android-5.1.1_r7android-5.1.1_r6android-5.1.1_r5android-5.1.1_r4android-5.1.1_r38android-5.1.1_r37android-5.1.1_r36android-5.1.1_r35android-5.1.1_r34android-5.1.1_r33android-5.1.1_r30android-5.1.1_r3android-5.1.1_r29android-5.1.1_r28android-5.1.1_r26android-5.1.1_r25android-5.1.1_r24android-5.1.1_r23android-5.1.1_r22android-5.1.1_r20android-5.1.1_r2android-5.1.1_r19android-5.1.1_r18android-5.1.1_r17android-5.1.1_r16android-5.1.1_r15android-5.1.1_r14android-5.1.1_r13android-5.1.1_r12android-5.1.1_r10android-5.1.1_r1android-5.1.0_r5android-5.1.0_r4android-5.1.0_r3android-5.1.0_r1android-5.0.2_r3android-5.0.2_r1android-5.0.1_r1android-5.0.0_r7android-5.0.0_r6android-5.0.0_r5.1android-5.0.0_r5android-5.0.0_r4android-5.0.0_r3android-5.0.0_r2android-5.0.0_r1lollipop-wear-releaselollipop-releaselollipop-mr1-wfc-releaselollipop-mr1-releaselollipop-mr1-fi-releaselollipop-mr1-devlollipop-mr1-cts-releaselollipop-devlollipop-cts-releasel-preview
./Eigen/src/Core/util/NonMPL2.h is left untouched, so that
usage of non MPL2 code is disabled.
Change-Id: I86fc9257b3c30d0ca15b268d4ef07bf038bba7ca
Diffstat (limited to 'unsupported/bench/bench_svd.cpp')
-rw-r--r-- | unsupported/bench/bench_svd.cpp | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/unsupported/bench/bench_svd.cpp b/unsupported/bench/bench_svd.cpp new file mode 100644 index 000000000..01d8231ae --- /dev/null +++ b/unsupported/bench/bench_svd.cpp @@ -0,0 +1,123 @@ +// This file is part of Eigen, a lightweight C++ template library +// for linear algebra. +// +// Copyright (C) 2013 Gauthier Brun <brun.gauthier@gmail.com> +// Copyright (C) 2013 Nicolas Carre <nicolas.carre@ensimag.fr> +// Copyright (C) 2013 Jean Ceccato <jean.ceccato@ensimag.fr> +// Copyright (C) 2013 Pierre Zoppitelli <pierre.zoppitelli@ensimag.fr> +// +// This Source Code Form is subject to the terms of the Mozilla +// Public License v. 2.0. If a copy of the MPL was not distributed +// with this file, You can obtain one at http://mozilla.org/MPL/2.0/ + +// Bench to compare the efficiency of SVD algorithms + +#include <iostream> +#include <bench/BenchTimer.h> +#include <unsupported/Eigen/SVD> + + +using namespace Eigen; +using namespace std; + +// number of computations of each algorithm before the print of the time +#ifndef REPEAT +#define REPEAT 10 +#endif + +// number of tests of the same type +#ifndef NUMBER_SAMPLE +#define NUMBER_SAMPLE 2 +#endif + +template<typename MatrixType> +void bench_svd(const MatrixType& a = MatrixType()) +{ + MatrixType m = MatrixType::Random(a.rows(), a.cols()); + BenchTimer timerJacobi; + BenchTimer timerBDC; + timerJacobi.reset(); + timerBDC.reset(); + + cout << " Only compute Singular Values" <<endl; + for (int k=1; k<=NUMBER_SAMPLE; ++k) + { + timerBDC.start(); + for (int i=0; i<REPEAT; ++i) + { + BDCSVD<MatrixType> bdc_matrix(m); + } + timerBDC.stop(); + + timerJacobi.start(); + for (int i=0; i<REPEAT; ++i) + { + JacobiSVD<MatrixType> jacobi_matrix(m); + } + timerJacobi.stop(); + + + cout << "Sample " << k << " : " << REPEAT << " computations : Jacobi : " << fixed << timerJacobi.value() << "s "; + cout << " || " << " BDC : " << timerBDC.value() << "s " <<endl <<endl; + + if (timerBDC.value() >= timerJacobi.value()) + cout << "KO : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" <<endl; + else + cout << "OK : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" <<endl; + + } + cout << " =================" <<endl; + std::cout<< std::endl; + timerJacobi.reset(); + timerBDC.reset(); + cout << " Computes rotaion matrix" <<endl; + for (int k=1; k<=NUMBER_SAMPLE; ++k) + { + timerBDC.start(); + for (int i=0; i<REPEAT; ++i) + { + BDCSVD<MatrixType> bdc_matrix(m, ComputeFullU|ComputeFullV); + } + timerBDC.stop(); + + timerJacobi.start(); + for (int i=0; i<REPEAT; ++i) + { + JacobiSVD<MatrixType> jacobi_matrix(m, ComputeFullU|ComputeFullV); + } + timerJacobi.stop(); + + + cout << "Sample " << k << " : " << REPEAT << " computations : Jacobi : " << fixed << timerJacobi.value() << "s "; + cout << " || " << " BDC : " << timerBDC.value() << "s " <<endl <<endl; + + if (timerBDC.value() >= timerJacobi.value()) + cout << "KO : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" <<endl; + else + cout << "OK : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" <<endl; + + } + std::cout<< std::endl; +} + + + +int main(int argc, char* argv[]) +{ + std::cout<< std::endl; + + std::cout<<"On a (Dynamic, Dynamic) (6, 6) Matrix" <<std::endl; + bench_svd<Matrix<double,Dynamic,Dynamic> >(Matrix<double,Dynamic,Dynamic>(6, 6)); + + std::cout<<"On a (Dynamic, Dynamic) (32, 32) Matrix" <<std::endl; + bench_svd<Matrix<double,Dynamic,Dynamic> >(Matrix<double,Dynamic,Dynamic>(32, 32)); + + //std::cout<<"On a (Dynamic, Dynamic) (128, 128) Matrix" <<std::endl; + //bench_svd<Matrix<double,Dynamic,Dynamic> >(Matrix<double,Dynamic,Dynamic>(128, 128)); + + std::cout<<"On a (Dynamic, Dynamic) (160, 160) Matrix" <<std::endl; + bench_svd<Matrix<double,Dynamic,Dynamic> >(Matrix<double,Dynamic,Dynamic>(160, 160)); + + std::cout<< "--------------------------------------------------------------------"<< std::endl; + +} |