From 8105b5ed3fd163f4b2574a2f0a6257cf119bab95 Mon Sep 17 00:00:00 2001 From: Gauthier Brun Date: Wed, 19 Jun 2013 00:03:27 +0200 Subject: new unsupported and not finished SVD, using a divide and conquert algorithm, with tests and benchmark --- unsupported/bench/bench_svd.cpp | 123 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 unsupported/bench/bench_svd.cpp (limited to 'unsupported/bench') 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 +// Copyright (C) 2013 Nicolas Carre +// Copyright (C) 2013 Jean Ceccato +// Copyright (C) 2013 Pierre Zoppitelli +// +// 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 +#include +#include + + +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 +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" < bdc_matrix(m); + } + timerBDC.stop(); + + timerJacobi.start(); + for (int i=0; i jacobi_matrix(m); + } + timerJacobi.stop(); + + + cout << "Sample " << k << " : " << REPEAT << " computations : Jacobi : " << fixed << timerJacobi.value() << "s "; + cout << " || " << " BDC : " << timerBDC.value() << "s " <= timerJacobi.value()) + cout << "KO : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" < bdc_matrix(m, ComputeFullU|ComputeFullV); + } + timerBDC.stop(); + + timerJacobi.start(); + for (int i=0; i jacobi_matrix(m, ComputeFullU|ComputeFullV); + } + timerJacobi.stop(); + + + cout << "Sample " << k << " : " << REPEAT << " computations : Jacobi : " << fixed << timerJacobi.value() << "s "; + cout << " || " << " BDC : " << timerBDC.value() << "s " <= timerJacobi.value()) + cout << "KO : BDC is " << timerJacobi.value() / timerBDC.value() << " times faster than Jacobi" < >(Matrix(6, 6)); + + std::cout<<"On a (Dynamic, Dynamic) (32, 32) Matrix" < >(Matrix(32, 32)); + + //std::cout<<"On a (Dynamic, Dynamic) (128, 128) Matrix" < >(Matrix(128, 128)); + + std::cout<<"On a (Dynamic, Dynamic) (160, 160) Matrix" < >(Matrix(160, 160)); + + std::cout<< "--------------------------------------------------------------------"<< std::endl; + +} -- cgit v1.2.3