From 44861dcbfeee041223c4aac1ee075e92fa4daa01 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 18 Sep 2016 12:42:15 +0200 Subject: update --- eigen/bench/BenchSparseUtil.h | 149 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 eigen/bench/BenchSparseUtil.h (limited to 'eigen/bench/BenchSparseUtil.h') diff --git a/eigen/bench/BenchSparseUtil.h b/eigen/bench/BenchSparseUtil.h new file mode 100644 index 0000000..13981f6 --- /dev/null +++ b/eigen/bench/BenchSparseUtil.h @@ -0,0 +1,149 @@ + +#include +#include +#include + +using namespace std; +using namespace Eigen; +using namespace Eigen; + +#ifndef SIZE +#define SIZE 1024 +#endif + +#ifndef DENSITY +#define DENSITY 0.01 +#endif + +#ifndef SCALAR +#define SCALAR double +#endif + +typedef SCALAR Scalar; +typedef Matrix DenseMatrix; +typedef Matrix DenseVector; +typedef SparseMatrix EigenSparseMatrix; + +void fillMatrix(float density, int rows, int cols, EigenSparseMatrix& dst) +{ + dst.reserve(double(rows)*cols*density); + for(int j = 0; j < cols; j++) + { + for(int i = 0; i < rows; i++) + { + Scalar v = (internal::random(0,1) < density) ? internal::random() : 0; + if (v!=0) + dst.insert(i,j) = v; + } + } + dst.finalize(); +} + +void fillMatrix2(int nnzPerCol, int rows, int cols, EigenSparseMatrix& dst) +{ +// std::cout << "alloc " << nnzPerCol*cols << "\n"; + dst.reserve(nnzPerCol*cols); + for(int j = 0; j < cols; j++) + { + std::set aux; + for(int i = 0; i < nnzPerCol; i++) + { + int k = internal::random(0,rows-1); + while (aux.find(k)!=aux.end()) + k = internal::random(0,rows-1); + aux.insert(k); + + dst.insert(k,j) = internal::random(); + } + } + dst.finalize(); +} + +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; +typedef mtl::compressed2D > MtlSparseRowMajor; +void eiToMtl(const EigenSparseMatrix& src, MtlSparse& dst) +{ + mtl::matrix::inserter ins(dst); + for (int j=0; j +#include +#include +#include +#include +#include +#include +#include + +typedef boost::numeric::ublas::compressed_matrix UBlasSparse; + +void eiToUblas(const EigenSparseMatrix& src, UBlasSparse& dst) +{ + dst.resize(src.rows(), src.cols(), false); + for (int j=0; j +void eiToUblasVec(const EigenType& src, UblasType& dst) +{ + dst.resize(src.size()); + for (int j=0; j +} +#endif -- cgit v1.2.3