Small performance improvement for matrix_augmented, with accompanying test in timeGaussianFactor

release/4.3a0
Alex Cunningham 2010-01-20 14:09:44 +00:00
parent 6bc0462669
commit 8db99db57e
2 changed files with 38 additions and 3 deletions

View File

@ -224,9 +224,9 @@ Matrix GaussianFactor::matrix_augmented(const Ordering& ordering, bool weight) c
} }
// load b into a matrix // load b into a matrix
Matrix B_mat(numberOfRows(), 1); size_t rows = b_.size();
for (int i=0; i<b_.size(); ++i) Matrix B_mat(rows, 1);
B_mat(i,0) = b_(i); memcpy(B_mat.data().begin(), b_.data().begin(), rows*sizeof(double));
matrices.push_back(&B_mat); matrices.push_back(&B_mat);
// divide in sigma so error is indeed 0.5*|Ax-b| // divide in sigma so error is indeed 0.5*|Ax-b|

View File

@ -13,11 +13,28 @@
using namespace std; using namespace std;
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include <boost/assign/std/list.hpp> // for operator += in Ordering
#include "Matrix.h" #include "Matrix.h"
#include "GaussianFactor.h" #include "GaussianFactor.h"
#include "GaussianConditional.h" #include "GaussianConditional.h"
#include "Ordering.h"
using namespace gtsam; using namespace gtsam;
using namespace boost::assign;
/*
* Alex's Machine
* Results for Eliminate:
* Initial (1891): 17.91 sec, 55834.7 calls/sec
*
* 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)
*/
int main() int main()
{ {
@ -69,6 +86,7 @@ int main()
b2(6) = 2; b2(6) = 2;
b2(7) = -1; b2(7) = -1;
// time eliminate
GaussianFactor combined("x2", Ax2, "l1", Al1, "x1", Ax1, b2,1); GaussianFactor combined("x2", Ax2, "l1", Al1, "x1", Ax1, b2,1);
long timeLog = clock(); long timeLog = clock();
int n = 1000000; int n = 1000000;
@ -80,7 +98,24 @@ int main()
long timeLog2 = clock(); long timeLog2 = clock();
double seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC; double seconds = (double)(timeLog2-timeLog)/CLOCKS_PER_SEC;
cout << "Single Eliminate Timing:" << endl;
cout << seconds << " seconds" << endl; cout << seconds << " seconds" << endl;
cout << ((double)n/seconds) << " calls/second" << endl; cout << ((double)n/seconds) << " calls/second" << endl;
// time matrix_augmented
Ordering ordering;
ordering += "x2", "l1", "x1";
size_t n1 = 10000000;
timeLog = clock();
for(int i = 0; i < n1; i++)
Matrix Ab = combined.matrix_augmented(ordering, true);
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;
return 0; return 0;
} }