diff options
author | Gael Guennebaud <g.gael@free.fr> | 2008-06-28 23:07:14 +0000 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2008-06-28 23:07:14 +0000 |
commit | 027818d7392dbb4f12db17bb9f35032727bb1a30 (patch) | |
tree | 437f31b0b222f9ad4d8e6351ba8dc6a0e00f1b8b /bench/BenchSparseUtil.h | |
parent | 6917be911311428567bbde2a5db430d8c2c9ef96 (diff) |
* 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 !
Diffstat (limited to 'bench/BenchSparseUtil.h')
-rw-r--r-- | bench/BenchSparseUtil.h | 75 |
1 files changed, 75 insertions, 0 deletions
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 <Eigen/Array> +#include <Eigen/Sparse> +#include <bench/BenchTimer.h> + + + +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<Scalar,Dynamic,Dynamic> DenseMatrix; +typedef SparseMatrix<Scalar> 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<float>(0,1) < density) ? ei_random<Scalar>() : 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<src.cols(); ++j) + for (EigenSparseMatrix::InnerIterator it(src.derived(), j); it; ++it) + dst(it.index(),j) = it.value(); +} + +#ifndef NOGMM +#include "gmm/gmm.h" +typedef gmm::csc_matrix<Scalar> GmmSparse; +typedef gmm::col_matrix< gmm::wsvector<Scalar> > GmmDynSparse; +void eiToGmm(const EigenSparseMatrix& src, GmmSparse& dst) +{ + GmmDynSparse tmp(src.rows(), src.cols()); + for (int j=0; j<src.cols(); ++j) + for (EigenSparseMatrix::InnerIterator it(src.derived(), j); it; ++it) + tmp(it.index(),j) = it.value(); + gmm::copy(tmp, dst); +} +#endif + +#ifndef NOMTL +#include <boost/numeric/mtl/mtl.hpp> +typedef mtl::compressed2D<Scalar> MtlSparse; +void eiToMtl(const EigenSparseMatrix& src, MtlSparse& dst) +{ + mtl::matrix::inserter<MtlSparse> ins(dst); + for (int j=0; j<src.cols(); ++j) + for (EigenSparseMatrix::InnerIterator it(src.derived(), j); it; ++it) + ins[it.index()][j] = it.value(); +} +#endif |