BenchUtil.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef EIGEN_BENCH_UTIL_H
  2. #define EIGEN_BENCH_UTIL_H
  3. #include <Eigen/Core>
  4. #include "BenchTimer.h"
  5. using namespace std;
  6. using namespace Eigen;
  7. #include <boost/preprocessor/repetition/enum_params.hpp>
  8. #include <boost/preprocessor/repetition.hpp>
  9. #include <boost/preprocessor/seq.hpp>
  10. #include <boost/preprocessor/array.hpp>
  11. #include <boost/preprocessor/arithmetic.hpp>
  12. #include <boost/preprocessor/comparison.hpp>
  13. #include <boost/preprocessor/punctuation.hpp>
  14. #include <boost/preprocessor/punctuation/comma.hpp>
  15. #include <boost/preprocessor/stringize.hpp>
  16. template<typename MatrixType> void initMatrix_random(MatrixType& mat) __attribute__((noinline));
  17. template<typename MatrixType> void initMatrix_random(MatrixType& mat)
  18. {
  19. mat.setRandom();// = MatrixType::random(mat.rows(), mat.cols());
  20. }
  21. template<typename MatrixType> void initMatrix_identity(MatrixType& mat) __attribute__((noinline));
  22. template<typename MatrixType> void initMatrix_identity(MatrixType& mat)
  23. {
  24. mat.setIdentity();
  25. }
  26. #ifndef __INTEL_COMPILER
  27. #define DISABLE_SSE_EXCEPTIONS() { \
  28. int aux; \
  29. asm( \
  30. "stmxcsr %[aux] \n\t" \
  31. "orl $32832, %[aux] \n\t" \
  32. "ldmxcsr %[aux] \n\t" \
  33. : : [aux] "m" (aux)); \
  34. }
  35. #else
  36. #define DISABLE_SSE_EXCEPTIONS()
  37. #endif
  38. #ifdef BENCH_GMM
  39. #include <gmm/gmm.h>
  40. template <typename EigenMatrixType, typename GmmMatrixType>
  41. void eiToGmm(const EigenMatrixType& src, GmmMatrixType& dst)
  42. {
  43. dst.resize(src.rows(),src.cols());
  44. for (int j=0; j<src.cols(); ++j)
  45. for (int i=0; i<src.rows(); ++i)
  46. dst(i,j) = src.coeff(i,j);
  47. }
  48. #endif
  49. #ifdef BENCH_GSL
  50. #include <gsl/gsl_matrix.h>
  51. #include <gsl/gsl_linalg.h>
  52. #include <gsl/gsl_eigen.h>
  53. template <typename EigenMatrixType>
  54. void eiToGsl(const EigenMatrixType& src, gsl_matrix** dst)
  55. {
  56. for (int j=0; j<src.cols(); ++j)
  57. for (int i=0; i<src.rows(); ++i)
  58. gsl_matrix_set(*dst, i, j, src.coeff(i,j));
  59. }
  60. #endif
  61. #ifdef BENCH_UBLAS
  62. #include <boost/numeric/ublas/matrix.hpp>
  63. #include <boost/numeric/ublas/vector.hpp>
  64. template <typename EigenMatrixType, typename UblasMatrixType>
  65. void eiToUblas(const EigenMatrixType& src, UblasMatrixType& dst)
  66. {
  67. dst.resize(src.rows(),src.cols());
  68. for (int j=0; j<src.cols(); ++j)
  69. for (int i=0; i<src.rows(); ++i)
  70. dst(i,j) = src.coeff(i,j);
  71. }
  72. template <typename EigenType, typename UblasType>
  73. void eiToUblasVec(const EigenType& src, UblasType& dst)
  74. {
  75. dst.resize(src.size());
  76. for (int j=0; j<src.size(); ++j)
  77. dst[j] = src.coeff(j);
  78. }
  79. #endif
  80. #endif // EIGEN_BENCH_UTIL_H