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