BenchUtil.h
Go to the documentation of this file.
1 
2 #ifndef EIGEN_BENCH_UTIL_H
3 #define EIGEN_BENCH_UTIL_H
4 
5 #include <Eigen/Core>
6 #include "BenchTimer.h"
7 
8 using namespace std;
9 using namespace Eigen;
10 
11 #include <boost/preprocessor/repetition/enum_params.hpp>
12 #include <boost/preprocessor/repetition.hpp>
13 #include <boost/preprocessor/seq.hpp>
14 #include <boost/preprocessor/array.hpp>
15 #include <boost/preprocessor/arithmetic.hpp>
16 #include <boost/preprocessor/comparison.hpp>
17 #include <boost/preprocessor/punctuation.hpp>
18 #include <boost/preprocessor/punctuation/comma.hpp>
19 #include <boost/preprocessor/stringize.hpp>
20 
21 template <typename MatrixType>
23 template <typename MatrixType>
25  mat.setRandom(); // = MatrixType::random(mat.rows(), mat.cols());
26 }
27 
28 template <typename MatrixType>
30 template <typename MatrixType>
32  mat.setIdentity();
33 }
34 
35 #ifndef __INTEL_COMPILER
36 #define DISABLE_SSE_EXCEPTIONS() \
37  { \
38  int aux; \
39  asm("stmxcsr %[aux] \n\t" \
40  "orl $32832, %[aux] \n\t" \
41  "ldmxcsr %[aux] \n\t" \
42  : \
43  : [aux] "m"(aux)); \
44  }
45 #else
46 #define DISABLE_SSE_EXCEPTIONS()
47 #endif
48 
49 #ifdef BENCH_GMM
50 #include <gmm/gmm.h>
51 template <typename EigenMatrixType, typename GmmMatrixType>
52 void eiToGmm(const EigenMatrixType& src, GmmMatrixType& dst) {
53  dst.resize(src.rows(), src.cols());
54  for (int j = 0; j < src.cols(); ++j)
55  for (int i = 0; i < src.rows(); ++i) dst(i, j) = src.coeff(i, j);
56 }
57 #endif
58 
59 #ifdef BENCH_GSL
60 #include <gsl/gsl_matrix.h>
61 #include <gsl/gsl_linalg.h>
62 #include <gsl/gsl_eigen.h>
63 template <typename EigenMatrixType>
64 void eiToGsl(const EigenMatrixType& src, gsl_matrix** dst) {
65  for (int j = 0; j < src.cols(); ++j)
66  for (int i = 0; i < src.rows(); ++i) gsl_matrix_set(*dst, i, j, src.coeff(i, j));
67 }
68 #endif
69 
70 #ifdef BENCH_UBLAS
71 #include <boost/numeric/ublas/matrix.hpp>
72 #include <boost/numeric/ublas/vector.hpp>
73 template <typename EigenMatrixType, typename UblasMatrixType>
74 void eiToUblas(const EigenMatrixType& src, UblasMatrixType& dst) {
75  dst.resize(src.rows(), src.cols());
76  for (int j = 0; j < src.cols(); ++j)
77  for (int i = 0; i < src.rows(); ++i) dst(i, j) = src.coeff(i, j);
78 }
79 template <typename EigenType, typename UblasType>
80 void eiToUblasVec(const EigenType& src, UblasType& dst) {
81  dst.resize(src.size());
82  for (int j = 0; j < src.size(); ++j) dst[j] = src.coeff(j);
83 }
84 #endif
85 
86 #endif // EIGEN_BENCH_UTIL_H
void eiToGmm(const EigenSparseMatrix &src, GmmSparse &dst)
Definition: BenchSparseUtil.h:64
void eiToUblasVec(const EigenType &src, UblasType &dst)
Definition: BenchSparseUtil.h:119
void eiToUblas(const EigenSparseMatrix &src, UBlasSparse &dst)
Definition: BenchSparseUtil.h:112
void initMatrix_identity(MatrixType &mat) __attribute__((noinline))
Definition: BenchUtil.h:31
void initMatrix_random(MatrixType &mat) __attribute__((noinline))
Definition: BenchUtil.h:24
int i
Definition: BiCGSTAB_step_by_step.cpp:9
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
void setIdentity()
Definition: SparseMatrix.h:842
svint32_t PacketXi __attribute__((arm_sve_vector_bits(EIGEN_ARM64_SVE_VL)))
Definition: SVE/PacketMath.h:34
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2