28 using namespace gtsam;
31 static std::mt19937
rng;
32 static std::uniform_real_distribution<>
uniform(0.0, 1.0);
34 int main(
int argc,
char *argv[]) {
40 size_t nBlocks = 4000;
44 double blockbuild, blocksolve, combbuild, combsolve;
46 cout <<
"\n1 variable of dimension " << vardim <<
", " <<
47 nBlocks <<
" blocks of dimension " << blockdim <<
"\n";
48 cout << nTrials <<
" trials\n";
55 cout <<
"Building blockwise Gaussian factor graphs... ";
58 vector<GaussianFactorGraph> blockGfgs;
59 blockGfgs.reserve(nTrials);
60 for(
size_t trial=0; trial<nTrials; ++trial) {
63 for(
size_t i=0;
i<nBlocks; ++
i) {
66 for(
size_t j=0;
j<blockdim; ++
j)
67 for(
size_t k=0; k<vardim; ++k)
70 for(
size_t j=0;
j<blockdim; ++
j)
72 blockGfgs[trial].push_back(std::make_shared<JacobianFactor>(key, A, b, noise));
77 blockbuild = blockbuildNode->secs();
78 cout << blockbuild <<
" s" << endl;
81 cout <<
"Solving blockwise Gaussian factor graphs... ";
84 for(
size_t trial=0; trial<nTrials; ++trial) {
91 blocksolve = blocksolveNode->secs();
92 cout << blocksolve <<
" s" << endl;
101 cout <<
"Building combined-factor Gaussian factor graphs... ";
104 vector<GaussianFactorGraph> combGfgs;
105 for(
size_t trial=0; trial<nTrials; ++trial) {
109 Matrix Acomb(blockdim*nBlocks, vardim);
110 Vector bcomb(blockdim*nBlocks);
111 for(
size_t i=0;
i<nBlocks; ++
i) {
113 for(
size_t j=0;
j<blockdim; ++
j)
114 for(
size_t k=0; k<vardim; ++k)
117 for(
size_t j=0;
j<blockdim; ++
j)
120 combGfgs[trial].push_back(std::make_shared<JacobianFactor>(key, Acomb, bcomb,
125 combbuild = combbuildNode->secs();
126 cout << combbuild <<
" s" << endl;
129 cout <<
"Solving combined-factor Gaussian factor graphs... ";
132 for(
size_t trial=0; trial<nTrials; ++trial) {
138 combsolve = combsolveNode->secs();
139 cout << combsolve <<
" s" << endl;
144 cout <<
"\nPer-factor-graph times for building and solving\n";
145 cout <<
"Blockwise: total " << (1000.0*(blockbuild+blocksolve)/
double(nTrials)) <<
146 " build " << (1000.0*blockbuild/
double(nTrials)) <<
147 " solve " << (1000.0*blocksolve/
double(nTrials)) <<
" ms/graph\n";
148 cout <<
"Combined: total " << (1000.0*(combbuild+combsolve)/
double(nTrials)) <<
149 " build " << (1000.0*combbuild/
double(nTrials)) <<
150 " solve " << (1000.0*combsolve/
double(nTrials)) <<
" ms/graph\n";
151 cout <<
"Fraction of time spent in overhead\n" <<
152 " total " << (((blockbuild+blocksolve)-(combbuild+combsolve)) / (blockbuild+blocksolve)) <<
"\n" <<
153 " build " << ((blockbuild-combbuild) / blockbuild) <<
"\n" <<
154 " solve " << ((blocksolve-combsolve) / blocksolve) <<
"\n";
const gtsam::Symbol key('X', 0)
#define tictoc_getNode(variable, label)
static std::uniform_real_distribution uniform(0.0, 1.0)
int main(int argc, char *argv[])
static const GaussianBayesNet gbn
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
std::shared_ptr< This > shared_ptr
Linear Factor Graph where all factors are Gaussians.
noiseModel::Diagonal::shared_ptr SharedDiagonal
Chordal Bayes Net, the result of eliminating a factor graph.
std::uint64_t Key
Integer nonlinear key type.
static shared_ptr Sigma(size_t dim, double sigma, bool smart=true)