eigen3_inverse.cpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Includes
11 *****************************************************************************/
12 
13 #include <iostream>
14 #include <ecl/linear_algebra.hpp>
15 #include <ecl/threads/priority.hpp>
16 #include <ecl/time/stopwatch.hpp>
17 #include <ecl/time/timestamp.hpp>
19 #include <ecl/formatters.hpp>
20 
21 /*****************************************************************************
22 ** Using
23 *****************************************************************************/
24 
26 using ecl::StopWatch;
27 using ecl::TimeStamp;
28 using Eigen::Matrix3f;
29 using Eigen::MatrixXf;
30 
31 /*****************************************************************************
32 ** Main
33 *****************************************************************************/
34 
35 int main(int argc, char **argv) {
36 
37  const unsigned int repeats = 10;
38  try {
39  ecl::set_priority(ecl::RealTimePriority4);
40  } catch ( StandardException &e ) {
41  // dont worry about it.
42  }
43  StopWatch stopwatch;
44  TimeStamp times[9];
45 
46  Matrix3f M3 = Matrix3f::Random();
47  Matrix3f M3I;
48  MatrixXf M100 = MatrixXf::Random(100,100);
49  MatrixXf M100I;
50 
51  // get rid of caching effects.
52  for ( unsigned int i = 0; i < repeats; ++i ) {
53  M3.inverse();
54  }
55 
56  times[0].stamp(0,0);
57  for ( unsigned int i = 0; i < repeats; ++i ) {
58  M3 = Matrix3f::Random();
59  stopwatch.restart();
60  M3I = M3.inverse();
61  times[0] += stopwatch.split();
62  }
63  times[1].stamp(0,0);
64  for ( unsigned int i = 0; i < repeats; ++i ) {
65  M100 = MatrixXf::Random(100,100);
66  stopwatch.restart();
67  M100I = M100.inverse();
68  times[1] += stopwatch.split();
69  }
70  times[2].stamp(0,0);
71  for ( unsigned int i = 0; i < repeats; ++i ) {
72  M100 = MatrixXf::Random(100,100);
73  stopwatch.restart();
74  M100I = M100.fullPivLu().inverse();
75  times[2] += stopwatch.split();
76  }
77 
79  std::cout << std::endl;
80  std::cout << "************** Eigen3 Inverse ***************" << std::endl;
81  std::cout << std::endl;
82  std::cout << " 3x3 (direct by val) : " << format(static_cast<double>(times[0])/static_cast<double>(repeats)) << std::endl;
83  std::cout << " 100x100 (PPivLU by val) : " << format(static_cast<double>(times[1])/static_cast<double>(repeats)) << std::endl;
84  std::cout << " 100x100 (FPivLU by val) : " << format(static_cast<double>(times[2])/static_cast<double>(repeats)) << std::endl;
85  std::cout << std::endl;
86 
87  return 0;
88 }
RealTimePriority4
int main(int argc, char **argv)
RightAlign


ecl_core_apps
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:55