An optimized version

release/4.3a0
dellaert 2014-10-03 14:35:39 +02:00
parent c20b588fe0
commit 3f017bf51f
1 changed files with 21 additions and 6 deletions

View File

@ -25,6 +25,7 @@
#include <time.h>
#include <iostream>
#include <iomanip> // std::setprecision
using namespace std;
using namespace gtsam;
@ -39,9 +40,18 @@ void time(const NonlinearFactor& f, const Values& values) {
long timeLog2 = clock();
double seconds = (double) (timeLog2 - timeLog) / CLOCKS_PER_SEC;
// cout << ((double) n / seconds) << " calls/second" << endl;
cout << setprecision(3);
cout << ((double) seconds * 1000000 / n) << " musecs/call" << endl;
}
boost::shared_ptr<Cal3_S2> fixedK(new Cal3_S2());
Point2 myProject(const Pose3& pose, const Point3& point,
boost::optional<Matrix&> H1, boost::optional<Matrix&> H2) {
PinholeCamera<Cal3_S2> camera(pose, *fixedK);
return camera.project(point, H1, H2);
}
int main() {
// Create leaves
@ -63,33 +73,38 @@ int main() {
// Dedicated factor
// Oct 3, 2014, Macbook Air
// 4.44887 musecs/call
// 4.2 musecs/call
GeneralSFMFactor2<Cal3_S2> oldFactor2(z, model, 1, 2, 3);
time(oldFactor2, values);
// BADFactor
// Oct 3, 2014, Macbook Air
// 20.7554 musecs/call
// 20.3 musecs/call
BADFactor<Point2> newFactor2(model, z,
uncalibrate(K, project(transform_to(x, p))));
time(newFactor2, values);
// CALIBRATED
boost::shared_ptr<Cal3_S2> fixedK(new Cal3_S2());
// Dedicated factor
// Oct 3, 2014, Macbook Air
// 3.69707 musecs/call
// 3.4 musecs/call
GenericProjectionFactor<Pose3, Point3> oldFactor1(z, model, 1, 2, fixedK);
time(oldFactor1, values);
// BADFactor
// Oct 3, 2014, Macbook Air
// 17.092 musecs/call
// 16.0 musecs/call
BADFactor<Point2> newFactor1(model, z,
uncalibrate(Cal3_S2_(*fixedK), project(transform_to(x, p))));
time(newFactor1, values);
// BADFactor, optimized
// Oct 3, 2014, Macbook Air
// 9.0 musecs/call
typedef PinholeCamera<Cal3_S2> Camera;
typedef Expression<Camera> Camera_;
BADFactor<Point2> newFactor3(model, z, Point2_(myProject, x, p));
time(newFactor3, values);
return 0;
}