From 611fc1789434f6b335f42739ed0d99b39c686da1 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 23 Mar 2011 11:39:35 +0100 Subject: add support for ublas --- bench/BenchSparseUtil.h | 20 +++++++------- bench/BenchUtil.h | 20 ++++++++++++++ bench/sparse_dense_product.cpp | 35 +++++++++++++++++++----- bench/sparse_product.cpp | 60 +++++++----------------------------------- 4 files changed, 70 insertions(+), 65 deletions(-) (limited to 'bench') diff --git a/bench/BenchSparseUtil.h b/bench/BenchSparseUtil.h index ff836bffe..13981f6b7 100644 --- a/bench/BenchSparseUtil.h +++ b/bench/BenchSparseUtil.h @@ -26,7 +26,7 @@ typedef SparseMatrix EigenSparseMatrix; void fillMatrix(float density, int rows, int cols, EigenSparseMatrix& dst) { - dst.reserve(rows*cols*density); + dst.reserve(double(rows)*cols*density); for(int j = 0; j < cols; j++) { for(int i = 0; i < rows; i++) @@ -122,22 +122,24 @@ void eiToCSparse(const EigenSparseMatrix& src, cs* &dst) #include #include #include -// #include -// using namespace boost; -// using namespace boost::numeric; -// using namespace boost::numeric::ublas; +typedef boost::numeric::ublas::compressed_matrix UBlasSparse; -typedef boost::numeric::ublas::compressed_matrix UblasMatrix; - -void eiToUblas(const EigenSparseMatrix& src, UblasMatrix& dst) +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 +#include +template +void eiToUblas(const EigenMatrixType& src, UblasMatrixType& dst) +{ + dst.resize(src.rows(),src.cols()); + for (int j=0; j +void eiToUblasVec(const EigenType& src, UblasType& dst) +{ + dst.resize(src.size()); + for (int j=0; j=MINDENSITY; density*=0.5) { - fillMatrix(density, rows, cols, sm1); + //fillMatrix(density, rows, cols, sm1); + fillMatrix2(7, rows, cols, sm1); // dense matrices #ifdef DENSEMATRIX @@ -76,14 +77,14 @@ int main(int argc, char *argv[]) for (int k=0; k uv1, uv2; + eiToUblasVec(v1,uv1); + eiToUblasVec(v2,uv2); + +// std::vector gmmV1(cols), gmmV2(cols); +// Map >(&gmmV1[0], cols) = v1; +// Map >(&gmmV2[0], cols) = v2; + + BENCH( uv2 = boost::numeric::ublas::prod(m1, uv1); ) + std::cout << " a * v:\t" << timer.value() << endl; + +// BENCH( boost::ublas::prod(gmm::transposed(m1), gmmV1, gmmV2); ) +// std::cout << " a' * v:\t" << timer.value() << endl; + } + #endif // MTL4 #ifndef NOMTL diff --git a/bench/sparse_product.cpp b/bench/sparse_product.cpp index 0b5558b89..d2fc44f0d 100644 --- a/bench/sparse_product.cpp +++ b/bench/sparse_product.cpp @@ -20,6 +20,7 @@ #include #include "BenchTimer.h" +#include "BenchUtil.h" #include "BenchSparseUtil.h" #ifndef NBTRIES @@ -228,16 +229,12 @@ int main(int argc, char *argv[]) eiToCSparse(sm1, m1); eiToCSparse(sm2, m2); -// timer.reset(); -// timer.start(); -// for (int k=0; k