From 027818d7392dbb4f12db17bb9f35032727bb1a30 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 28 Jun 2008 23:07:14 +0000 Subject: * added innerSize / outerSize functions to MatrixBase * added complete implementation of sparse matrix product (with a little glue in Eigen/Core) * added an exhaustive bench of sparse products including GMM++ and MTL4 => Eigen outperforms in all transposed/density configurations ! --- bench/BenchSparseUtil.h | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 bench/BenchSparseUtil.h (limited to 'bench/BenchSparseUtil.h') diff --git a/bench/BenchSparseUtil.h b/bench/BenchSparseUtil.h new file mode 100644 index 000000000..97838f4b1 --- /dev/null +++ b/bench/BenchSparseUtil.h @@ -0,0 +1,75 @@ + +#include +#include +#include + + + +using namespace std; +using namespace Eigen; +USING_PART_OF_NAMESPACE_EIGEN + +#ifndef SIZE +#define SIZE 1024 +#endif + +#ifndef DENSITY +#define DENSITY 0.01 +#endif + +#ifndef SCALAR +#define SCALAR float +#endif + +typedef SCALAR Scalar; +typedef Matrix DenseMatrix; +typedef SparseMatrix EigenSparseMatrix; + +void fillMatrix(float density, int rows, int cols, EigenSparseMatrix& dst) +{ + dst.startFill(rows*cols*density); + for(int j = 0; j < cols; j++) + { + for(int i = 0; i < rows; i++) + { + Scalar v = (ei_random(0,1) < density) ? ei_random() : 0; + if (v!=0) + dst.fill(i,j) = v; + } + } + dst.endFill(); +} + +void eiToDense(const EigenSparseMatrix& src, DenseMatrix& dst) +{ + dst.setZero(); + for (int j=0; j GmmSparse; +typedef gmm::col_matrix< gmm::wsvector > GmmDynSparse; +void eiToGmm(const EigenSparseMatrix& src, GmmSparse& dst) +{ + GmmDynSparse tmp(src.rows(), src.cols()); + for (int j=0; j +typedef mtl::compressed2D MtlSparse; +void eiToMtl(const EigenSparseMatrix& src, MtlSparse& dst) +{ + mtl::matrix::inserter ins(dst); + for (int j=0; j