2010-10-14 12:54:38 +08:00
|
|
|
/* ----------------------------------------------------------------------------
|
|
|
|
|
2019-02-11 22:39:48 +08:00
|
|
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
2010-10-14 12:54:38 +08:00
|
|
|
* Atlanta, Georgia 30332-0415
|
|
|
|
* All Rights Reserved
|
|
|
|
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
|
|
|
|
|
|
|
* See LICENSE for the license information
|
|
|
|
|
|
|
|
* -------------------------------------------------------------------------- */
|
|
|
|
|
2009-08-22 06:23:24 +08:00
|
|
|
/**
|
2009-11-13 00:16:32 +08:00
|
|
|
* @file timeGaussianFactor.cpp
|
2011-01-21 06:22:00 +08:00
|
|
|
* @brief time JacobianFactor.eliminate
|
2009-08-22 06:23:24 +08:00
|
|
|
* @author Alireza Fathi
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
/*STL/C++*/
|
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
|
2010-01-20 22:09:44 +08:00
|
|
|
|
2010-08-20 01:23:19 +08:00
|
|
|
#include <gtsam/base/Matrix.h>
|
2011-01-21 06:22:00 +08:00
|
|
|
#include <gtsam/linear/JacobianFactor.h>
|
|
|
|
#include <gtsam/linear/JacobianFactor.h>
|
2010-08-20 01:23:19 +08:00
|
|
|
#include <gtsam/linear/GaussianConditional.h>
|
2012-10-03 02:36:39 +08:00
|
|
|
#include <gtsam/linear/NoiseModel.h>
|
2009-08-22 06:23:24 +08:00
|
|
|
|
|
|
|
using namespace gtsam;
|
2010-01-20 22:09:44 +08:00
|
|
|
|
2014-06-08 10:02:11 +08:00
|
|
|
static const Key _x1_=1, _x2_=2, _l1_=3;
|
2010-10-09 06:04:47 +08:00
|
|
|
|
2010-01-20 22:09:44 +08:00
|
|
|
/*
|
|
|
|
* Alex's Machine
|
|
|
|
* Results for Eliminate:
|
|
|
|
* Initial (1891): 17.91 sec, 55834.7 calls/sec
|
2010-01-27 13:08:54 +08:00
|
|
|
* NoiseQR : 11.69 sec
|
2010-01-20 22:09:44 +08:00
|
|
|
*
|
|
|
|
* Results for matrix_augmented:
|
|
|
|
* Initial (1891) : 0.85 sec, 1.17647e+06 calls/sec
|
|
|
|
* int->size_t Version : 8.45 sec (for n1 reps) with memcpy version of collect()
|
|
|
|
* w/ original collect(): 8.73 sec (for n1 reps)
|
|
|
|
* b memcpy Version : 8.64 sec (for n1 reps) with original version of collect()
|
|
|
|
* w/ memcpy collect() : 8.40 sec (for n1 reps)
|
2010-01-27 13:08:54 +08:00
|
|
|
* Rev 2100 : 8.15 sec
|
2010-01-20 22:09:44 +08:00
|
|
|
*/
|
2009-08-22 06:23:24 +08:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
// create a linear factor
|
2014-06-08 10:02:11 +08:00
|
|
|
Matrix Ax2 = (Matrix(8, 2) <<
|
2019-02-11 22:39:48 +08:00
|
|
|
// x2
|
2012-10-02 22:40:07 +08:00
|
|
|
-5., 0.,
|
|
|
|
+0.,-5.,
|
|
|
|
10., 0.,
|
|
|
|
+0.,10.,
|
|
|
|
-5., 0.,
|
|
|
|
+0.,-5.,
|
|
|
|
10., 0.,
|
|
|
|
+0.,10.
|
2014-11-23 10:07:27 +08:00
|
|
|
).finished();
|
2019-02-11 22:39:48 +08:00
|
|
|
|
2014-06-08 10:02:11 +08:00
|
|
|
Matrix Al1 = (Matrix(8, 10) <<
|
2019-02-11 22:39:48 +08:00
|
|
|
// l1
|
2012-10-02 22:40:07 +08:00
|
|
|
5., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
|
|
|
|
0., 5.,1.,2.,3.,4.,5.,6.,7.,8.,
|
|
|
|
0., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
|
|
|
|
0., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
|
|
|
|
5., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
|
|
|
|
0., 5.,1.,2.,3.,4.,5.,6.,7.,8.,
|
|
|
|
0., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
|
|
|
|
0., 0.,1.,2.,3.,4.,5.,6.,7.,8.
|
2014-11-23 10:07:27 +08:00
|
|
|
).finished();
|
2019-02-11 22:39:48 +08:00
|
|
|
|
2014-06-08 10:02:11 +08:00
|
|
|
Matrix Ax1 = (Matrix(8, 2) <<
|
2012-10-02 22:40:07 +08:00
|
|
|
// x1
|
|
|
|
0.00, 0.,1.,2.,3.,4.,5.,6.,7.,8.,
|
|
|
|
0.00, 0.,1.,2.,3.,4.,5.,6.,7.,8.,
|
|
|
|
-10., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
|
|
|
|
0.00,-10.,1.,2.,3.,4.,5.,6.,7.,8.,
|
|
|
|
0.00, 0.,1.,2.,3.,4.,5.,6.,7.,8.,
|
|
|
|
0.00, 0.,1.,2.,3.,4.,5.,6.,7.,8.,
|
|
|
|
-10., 0.,1.,2.,3.,4.,5.,6.,7.,8.,
|
|
|
|
0.00,-10.,1.,2.,3.,4.,5.,6.,7.,8.
|
2014-11-23 10:07:27 +08:00
|
|
|
).finished();
|
2009-08-22 06:23:24 +08:00
|
|
|
|
|
|
|
// and a RHS
|
|
|
|
Vector b2(8);
|
|
|
|
b2(0) = -1;
|
|
|
|
b2(1) = 1.5;
|
|
|
|
b2(2) = 2;
|
|
|
|
b2(3) = -1;
|
|
|
|
b2(4) = -1;
|
|
|
|
b2(5) = 1.5;
|
|
|
|
b2(6) = 2;
|
|
|
|
b2(7) = -1;
|
2019-02-11 22:39:48 +08:00
|
|
|
|
2010-01-20 22:09:44 +08:00
|
|
|
// time eliminate
|
2012-06-23 03:36:49 +08:00
|
|
|
JacobianFactor combined(_x2_, Ax2, _l1_, Al1, _x1_, Ax1, b2, noiseModel::Isotropic::Sigma(8,1));
|
2009-08-22 06:23:24 +08:00
|
|
|
long timeLog = clock();
|
|
|
|
int n = 1000000;
|
2009-11-13 00:41:18 +08:00
|
|
|
GaussianConditional::shared_ptr conditional;
|
2011-01-21 06:22:00 +08:00
|
|
|
JacobianFactor::shared_ptr factor;
|
2009-08-22 06:23:24 +08:00
|
|
|
|
|
|
|
for(int i = 0; i < n; i++)
|
2023-01-19 08:32:29 +08:00
|
|
|
std::tie(conditional, factor) =
|
2023-01-08 15:58:35 +08:00
|
|
|
JacobianFactor(combined).eliminate(Ordering{_x2_});
|
2009-08-22 06:23:24 +08:00
|
|
|
|
|
|
|
long timeLog2 = clock();
|
|
|
|
double seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC;
|
2010-01-20 22:09:44 +08:00
|
|
|
cout << "Single Eliminate Timing:" << endl;
|
2009-08-22 06:23:24 +08:00
|
|
|
cout << seconds << " seconds" << endl;
|
|
|
|
cout << ((double)n/seconds) << " calls/second" << endl;
|
2010-01-20 22:09:44 +08:00
|
|
|
|
|
|
|
// time matrix_augmented
|
2023-02-06 08:37:04 +08:00
|
|
|
// const Ordering ordering{_x2_, _l1_, _x1_};
|
2010-10-09 06:04:47 +08:00
|
|
|
// size_t n1 = 10000000;
|
|
|
|
// timeLog = clock();
|
|
|
|
//
|
|
|
|
// for(size_t i = 0; i < n1; i++)
|
2012-10-02 22:40:07 +08:00
|
|
|
// Matrix Ab = combined.matrix_augmented(ordering, true);
|
2010-10-09 06:04:47 +08:00
|
|
|
//
|
|
|
|
// timeLog2 = clock();
|
|
|
|
// seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC;
|
|
|
|
// cout << "matrix_augmented Timing:" << endl;
|
|
|
|
// cout << seconds << " seconds" << endl;
|
|
|
|
// cout << ((double)n/seconds) << " calls/second" << endl;
|
2010-01-20 22:09:44 +08:00
|
|
|
|
2009-08-22 06:23:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|