eigen3_inverse.cpp
Go to the documentation of this file.
00001 
00009 /*****************************************************************************
00010 ** Includes
00011 *****************************************************************************/
00012 
00013 #include <iostream>
00014 #include <ecl/linear_algebra.hpp>
00015 #include <ecl/threads/priority.hpp>
00016 #include <ecl/time/stopwatch.hpp>
00017 #include <ecl/time/timestamp.hpp>
00018 #include <ecl/exceptions/standard_exception.hpp>
00019 #include <ecl/formatters.hpp>
00020 
00021 /*****************************************************************************
00022 ** Using
00023 *****************************************************************************/
00024 
00025 using ecl::StandardException;
00026 using ecl::StopWatch;
00027 using ecl::TimeStamp;
00028 using Eigen::Matrix3f;
00029 using Eigen::MatrixXf;
00030 
00031 /*****************************************************************************
00032 ** Main
00033 *****************************************************************************/
00034 
00035 int main(int argc, char **argv) {
00036 
00037         const unsigned int repeats = 10;
00038         try {
00039                 ecl::set_priority(ecl::RealTimePriority4);
00040         } catch ( StandardException &e ) {
00041                 // dont worry about it.
00042         }
00043     StopWatch stopwatch;
00044     TimeStamp times[9];
00045 
00046     Matrix3f M3 = Matrix3f::Random();
00047     Matrix3f M3I;
00048     MatrixXf M100 = MatrixXf::Random(100,100);
00049     MatrixXf M100I;
00050 
00051     // get rid of caching effects.
00052     for ( unsigned int i = 0; i < repeats; ++i ) {
00053         M3.inverse();
00054     }
00055 
00056     times[0].stamp(0,0);
00057     for ( unsigned int i = 0; i < repeats; ++i ) {
00058         M3 = Matrix3f::Random();
00059         stopwatch.restart();
00060         M3I = M3.inverse();
00061         times[0] += stopwatch.split();
00062     }
00063     times[1].stamp(0,0);
00064     for ( unsigned int i = 0; i < repeats; ++i ) {
00065         M100 = MatrixXf::Random(100,100);
00066         stopwatch.restart();
00067         M100I = M100.inverse();
00068         times[1] += stopwatch.split();
00069     }
00070     times[2].stamp(0,0);
00071     for ( unsigned int i = 0; i < repeats; ++i ) {
00072         M100 = MatrixXf::Random(100,100);
00073         stopwatch.restart();
00074         M100I = M100.fullPivLu().inverse();
00075         times[2] += stopwatch.split();
00076     }
00077 
00078     ecl::Format<double> format(15,9,ecl::RightAlign);
00079     std::cout << std::endl;
00080     std::cout << "************** Eigen3 Inverse ***************" << std::endl;
00081     std::cout << std::endl;
00082     std::cout << "   3x3   (direct by val) : " << format(static_cast<double>(times[0])/static_cast<double>(repeats)) << std::endl;
00083     std::cout << " 100x100 (PPivLU by val) : " << format(static_cast<double>(times[1])/static_cast<double>(repeats)) << std::endl;
00084     std::cout << " 100x100 (FPivLU by val) : " << format(static_cast<double>(times[2])/static_cast<double>(repeats)) << std::endl;
00085     std::cout << std::endl;
00086 
00087         return 0;
00088 }


ecl_core_apps
Author(s): Daniel Stonier
autogenerated on Sun Oct 5 2014 23:36:25