diff options
author | Narayan Kamath <narayan@google.com> | 2012-11-02 10:59:05 +0000 |
---|---|---|
committer | Xiaotao Duan <xiaotao@google.com> | 2012-11-07 14:17:48 -0800 |
commit | c981c48f5bc9aefeffc0bcb0cc3934c2fae179dd (patch) | |
tree | 54d1c7d66098154c1d7c5bd414394ef4cf255810 /bench/benchCholesky.cpp | |
parent | 63f67d748682b46d58be31235a0a2d64d81b998c (diff) | |
download | eigen-c981c48f5bc9aefeffc0bcb0cc3934c2fae179dd.tar.gz |
Initial import of eigen 3.1.1android-cts-4.4_r4android-cts-4.2_r2android-4.4_r1.2.0.1android-4.4_r1.2android-4.4_r1.1.0.1android-4.4_r1.1android-4.4_r1.0.1android-4.4_r1android-4.4_r0.9android-4.4_r0.8android-4.3_r2.3android-4.3_r2.2android-4.3_r2.1android-4.3_r2android-4.3_r1.1android-4.3_r1android-4.3_r0.9.1android-4.3_r0.9android-4.2.2_r1.2android-4.2.2_r1.1android-4.2.2_r1kitkat-releasekitkat-cts-releasejb-mr2.0-releasejb-mr2-releasejb-mr1.1-releasejb-mr1.1-dev
Added a README.android and a MODULE_LICENSE_MPL2 file.
Added empty Android.mk and CleanSpec.mk to optimize Android build.
Non MPL2 license code is disabled in ./Eigen/src/Core/util/NonMPL2.h.
Trying to include such files will lead to an error.
Change-Id: I0e148b7c3e83999bcc4dfaa5809d33bfac2aac32
Diffstat (limited to 'bench/benchCholesky.cpp')
-rw-r--r-- | bench/benchCholesky.cpp | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/bench/benchCholesky.cpp b/bench/benchCholesky.cpp new file mode 100644 index 000000000..42b3e1285 --- /dev/null +++ b/bench/benchCholesky.cpp @@ -0,0 +1,142 @@ + +// g++ -DNDEBUG -O3 -I.. benchLLT.cpp -o benchLLT && ./benchLLT +// options: +// -DBENCH_GSL -lgsl /usr/lib/libcblas.so.3 +// -DEIGEN_DONT_VECTORIZE +// -msse2 +// -DREPEAT=100 +// -DTRIES=10 +// -DSCALAR=double + +#include <iostream> + +#include <Eigen/Core> +#include <Eigen/Cholesky> +#include <bench/BenchUtil.h> +using namespace Eigen; + +#ifndef REPEAT +#define REPEAT 10000 +#endif + +#ifndef TRIES +#define TRIES 10 +#endif + +typedef float Scalar; + +template <typename MatrixType> +__attribute__ ((noinline)) void benchLLT(const MatrixType& m) +{ + int rows = m.rows(); + int cols = m.cols(); + + int cost = 0; + for (int j=0; j<rows; ++j) + { + int r = std::max(rows - j -1,0); + cost += 2*(r*j+r+j); + } + + int repeats = (REPEAT*1000)/(rows*rows); + + typedef typename MatrixType::Scalar Scalar; + typedef Matrix<Scalar, MatrixType::RowsAtCompileTime, MatrixType::RowsAtCompileTime> SquareMatrixType; + + MatrixType a = MatrixType::Random(rows,cols); + SquareMatrixType covMat = a * a.adjoint(); + + BenchTimer timerNoSqrt, timerSqrt; + + Scalar acc = 0; + int r = internal::random<int>(0,covMat.rows()-1); + int c = internal::random<int>(0,covMat.cols()-1); + for (int t=0; t<TRIES; ++t) + { + timerNoSqrt.start(); + for (int k=0; k<repeats; ++k) + { + LDLT<SquareMatrixType> cholnosqrt(covMat); + acc += cholnosqrt.matrixL().coeff(r,c); + } + timerNoSqrt.stop(); + } + + for (int t=0; t<TRIES; ++t) + { + timerSqrt.start(); + for (int k=0; k<repeats; ++k) + { + LLT<SquareMatrixType> chol(covMat); + acc += chol.matrixL().coeff(r,c); + } + timerSqrt.stop(); + } + + if (MatrixType::RowsAtCompileTime==Dynamic) + std::cout << "dyn "; + else + std::cout << "fixed "; + std::cout << covMat.rows() << " \t" + << (timerNoSqrt.value() * REPEAT) / repeats << "s " + << "(" << 1e-6 * cost*repeats/timerNoSqrt.value() << " MFLOPS)\t" + << (timerSqrt.value() * REPEAT) / repeats << "s " + << "(" << 1e-6 * cost*repeats/timerSqrt.value() << " MFLOPS)\n"; + + + #ifdef BENCH_GSL + if (MatrixType::RowsAtCompileTime==Dynamic) + { + timerSqrt.reset(); + + gsl_matrix* gslCovMat = gsl_matrix_alloc(covMat.rows(),covMat.cols()); + gsl_matrix* gslCopy = gsl_matrix_alloc(covMat.rows(),covMat.cols()); + + eiToGsl(covMat, &gslCovMat); + for (int t=0; t<TRIES; ++t) + { + timerSqrt.start(); + for (int k=0; k<repeats; ++k) + { + gsl_matrix_memcpy(gslCopy,gslCovMat); + gsl_linalg_cholesky_decomp(gslCopy); + acc += gsl_matrix_get(gslCopy,r,c); + } + timerSqrt.stop(); + } + + std::cout << " | \t" + << timerSqrt.value() * REPEAT / repeats << "s"; + + gsl_matrix_free(gslCovMat); + } + #endif + std::cout << "\n"; + // make sure the compiler does not optimize too much + if (acc==123) + std::cout << acc; +} + +int main(int argc, char* argv[]) +{ + const int dynsizes[] = {4,6,8,16,24,32,49,64,128,256,512,900,0}; + std::cout << "size no sqrt standard"; +// #ifdef BENCH_GSL +// std::cout << " GSL (standard + double + ATLAS) "; +// #endif + std::cout << "\n"; + for (uint i=0; dynsizes[i]>0; ++i) + benchLLT(Matrix<Scalar,Dynamic,Dynamic>(dynsizes[i],dynsizes[i])); + + benchLLT(Matrix<Scalar,2,2>()); + benchLLT(Matrix<Scalar,3,3>()); + benchLLT(Matrix<Scalar,4,4>()); + benchLLT(Matrix<Scalar,5,5>()); + benchLLT(Matrix<Scalar,6,6>()); + benchLLT(Matrix<Scalar,7,7>()); + benchLLT(Matrix<Scalar,8,8>()); + benchLLT(Matrix<Scalar,12,12>()); + benchLLT(Matrix<Scalar,16,16>()); + return 0; +} + |