sparse_transpose.cpp
Go to the documentation of this file.
00001 
00002 //g++ -O3 -g0 -DNDEBUG  sparse_transpose.cpp -I.. -I/home/gael/Coding/LinearAlgebra/mtl4/ -DDENSITY=0.005 -DSIZE=10000 && ./a.out
00003 // -DNOGMM -DNOMTL
00004 // -DCSPARSE -I /home/gael/Coding/LinearAlgebra/CSparse/Include/ /home/gael/Coding/LinearAlgebra/CSparse/Lib/libcsparse.a
00005 
00006 #ifndef SIZE
00007 #define SIZE 10000
00008 #endif
00009 
00010 #ifndef DENSITY
00011 #define DENSITY 0.01
00012 #endif
00013 
00014 #ifndef REPEAT
00015 #define REPEAT 1
00016 #endif
00017 
00018 #include "BenchSparseUtil.h"
00019 
00020 #ifndef MINDENSITY
00021 #define MINDENSITY 0.0004
00022 #endif
00023 
00024 #ifndef NBTRIES
00025 #define NBTRIES 10
00026 #endif
00027 
00028 #define BENCH(X) \
00029   timer.reset(); \
00030   for (int _j=0; _j<NBTRIES; ++_j) { \
00031     timer.start(); \
00032     for (int _k=0; _k<REPEAT; ++_k) { \
00033         X  \
00034   } timer.stop(); }
00035 
00036 int main(int argc, char *argv[])
00037 {
00038   int rows = SIZE;
00039   int cols = SIZE;
00040   float density = DENSITY;
00041 
00042   EigenSparseMatrix sm1(rows,cols), sm3(rows,cols);
00043 
00044   BenchTimer timer;
00045   for (float density = DENSITY; density>=MINDENSITY; density*=0.5)
00046   {
00047     fillMatrix(density, rows, cols, sm1);
00048 
00049     // dense matrices
00050     #ifdef DENSEMATRIX
00051     {
00052       DenseMatrix m1(rows,cols), m3(rows,cols);
00053       eiToDense(sm1, m1);
00054       BENCH(for (int k=0; k<REPEAT; ++k) m3 = m1.transpose();)
00055       std::cout << "  Eigen dense:\t" << timer.value() << endl;
00056     }
00057     #endif
00058 
00059     std::cout << "Non zeros: " << sm1.nonZeros()/float(sm1.rows()*sm1.cols())*100 << "%\n";
00060 
00061     // eigen sparse matrices
00062     {
00063       BENCH(for (int k=0; k<REPEAT; ++k) sm3 = sm1.transpose();)
00064       std::cout << "  Eigen:\t" << timer.value() << endl;
00065     }
00066 
00067     // CSparse
00068     #ifdef CSPARSE
00069     {
00070       cs *m1, *m3;
00071       eiToCSparse(sm1, m1);
00072 
00073       BENCH(for (int k=0; k<REPEAT; ++k) { m3 = cs_transpose(m1,1); cs_spfree(m3);})
00074       std::cout << "  CSparse:\t" << timer.value() << endl;
00075     }
00076     #endif
00077 
00078     // GMM++
00079     #ifndef NOGMM
00080     {
00081       GmmDynSparse  gmmT3(rows,cols);
00082       GmmSparse m1(rows,cols), m3(rows,cols);
00083       eiToGmm(sm1, m1);
00084       BENCH(for (int k=0; k<REPEAT; ++k) gmm::copy(gmm::transposed(m1),m3);)
00085       std::cout << "  GMM:\t\t" << timer.value() << endl;
00086     }
00087     #endif
00088 
00089     // MTL4
00090     #ifndef NOMTL
00091     {
00092       MtlSparse m1(rows,cols), m3(rows,cols);
00093       eiToMtl(sm1, m1);
00094       BENCH(for (int k=0; k<REPEAT; ++k) m3 = trans(m1);)
00095       std::cout << "  MTL4:\t\t" << timer.value() << endl;
00096     }
00097     #endif
00098 
00099     std::cout << "\n\n";
00100   }
00101 
00102   return 0;
00103 }
00104 


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:46