Merge branch 'develop' into feature/LPSolver

# Conflicts:
#	gtsam_unstable/linear/QPSolver.cpp
#	gtsam_unstable/linear/QPSolver.h
release/4.3a0
ivan 2016-05-30 14:12:15 -04:00
commit 2e4a94e2bb
202 changed files with 861 additions and 993 deletions

View File

@ -18,7 +18,6 @@
#include <gtsam/slam/dataset.h> #include <gtsam/slam/dataset.h>
#include <gtsam/geometry/CalibratedCamera.h> #include <gtsam/geometry/CalibratedCamera.h>
#include <boost/foreach.hpp>
#include <boost/assign/std/vector.hpp> #include <boost/assign/std/vector.hpp>
using namespace boost::assign; using namespace boost::assign;
@ -41,7 +40,7 @@ void createExampleBALFile(const string& filename, const vector<Point3>& P,
data.cameras.push_back(SfM_Camera(pose1, K)); data.cameras.push_back(SfM_Camera(pose1, K));
data.cameras.push_back(SfM_Camera(pose2, K)); data.cameras.push_back(SfM_Camera(pose2, K));
BOOST_FOREACH(const Point3& p, P) { for(const Point3& p: P) {
// Create the track // Create the track
SfM_Track track; SfM_Track track;

View File

@ -56,7 +56,7 @@ int main(const int argc, const char *argv[]) {
std::cout << "Rewriting input to file: " << inputFileRewritten << std::endl; std::cout << "Rewriting input to file: " << inputFileRewritten << std::endl;
// Additional: rewrite input with simplified keys 0,1,... // Additional: rewrite input with simplified keys 0,1,...
Values simpleInitial; Values simpleInitial;
BOOST_FOREACH(const Values::ConstKeyValuePair& key_value, *initial) { for(const Values::ConstKeyValuePair& key_value: *initial) {
Key key; Key key;
if(add) if(add)
key = key_value.key + firstKey; key = key_value.key + firstKey;
@ -66,7 +66,7 @@ int main(const int argc, const char *argv[]) {
simpleInitial.insert(key, initial->at(key_value.key)); simpleInitial.insert(key, initial->at(key_value.key));
} }
NonlinearFactorGraph simpleGraph; NonlinearFactorGraph simpleGraph;
BOOST_FOREACH(const boost::shared_ptr<NonlinearFactor>& factor, *graph) { for(const boost::shared_ptr<NonlinearFactor>& factor: *graph) {
boost::shared_ptr<BetweenFactor<Pose3> > pose3Between = boost::shared_ptr<BetweenFactor<Pose3> > pose3Between =
boost::dynamic_pointer_cast<BetweenFactor<Pose3> >(factor); boost::dynamic_pointer_cast<BetweenFactor<Pose3> >(factor);
if (pose3Between){ if (pose3Between){

View File

@ -45,7 +45,7 @@ int main(const int argc, const char *argv[]) {
noiseModel::Diagonal::shared_ptr priorModel = // noiseModel::Diagonal::shared_ptr priorModel = //
noiseModel::Diagonal::Variances((Vector(6) << 1e-6, 1e-6, 1e-6, 1e-4, 1e-4, 1e-4).finished()); noiseModel::Diagonal::Variances((Vector(6) << 1e-6, 1e-6, 1e-6, 1e-4, 1e-4, 1e-4).finished());
Key firstKey = 0; Key firstKey = 0;
BOOST_FOREACH(const Values::ConstKeyValuePair& key_value, *initial) { for(const Values::ConstKeyValuePair& key_value: *initial) {
std::cout << "Adding prior to g2o file " << std::endl; std::cout << "Adding prior to g2o file " << std::endl;
firstKey = key_value.key; firstKey = key_value.key;
graphWithPrior.add(PriorFactor<Pose3>(firstKey, Pose3(), priorModel)); graphWithPrior.add(PriorFactor<Pose3>(firstKey, Pose3(), priorModel));

View File

@ -45,7 +45,7 @@ int main(const int argc, const char *argv[]) {
noiseModel::Diagonal::shared_ptr priorModel = // noiseModel::Diagonal::shared_ptr priorModel = //
noiseModel::Diagonal::Variances((Vector(6) << 1e-6, 1e-6, 1e-6, 1e-4, 1e-4, 1e-4).finished()); noiseModel::Diagonal::Variances((Vector(6) << 1e-6, 1e-6, 1e-6, 1e-4, 1e-4, 1e-4).finished());
Key firstKey = 0; Key firstKey = 0;
BOOST_FOREACH(const Values::ConstKeyValuePair& key_value, *initial) { for(const Values::ConstKeyValuePair& key_value: *initial) {
std::cout << "Adding prior to g2o file " << std::endl; std::cout << "Adding prior to g2o file " << std::endl;
firstKey = key_value.key; firstKey = key_value.key;
graphWithPrior.add(PriorFactor<Pose3>(firstKey, Pose3(), priorModel)); graphWithPrior.add(PriorFactor<Pose3>(firstKey, Pose3(), priorModel));

View File

@ -45,7 +45,7 @@ int main(const int argc, const char *argv[]) {
noiseModel::Diagonal::shared_ptr priorModel = // noiseModel::Diagonal::shared_ptr priorModel = //
noiseModel::Diagonal::Variances((Vector(6) << 1e-6, 1e-6, 1e-6, 1e-4, 1e-4, 1e-4).finished()); noiseModel::Diagonal::Variances((Vector(6) << 1e-6, 1e-6, 1e-6, 1e-4, 1e-4, 1e-4).finished());
Key firstKey = 0; Key firstKey = 0;
BOOST_FOREACH(const Values::ConstKeyValuePair& key_value, *initial) { for(const Values::ConstKeyValuePair& key_value: *initial) {
std::cout << "Adding prior to g2o file " << std::endl; std::cout << "Adding prior to g2o file " << std::endl;
firstKey = key_value.key; firstKey = key_value.key;
graphWithPrior.add(PriorFactor<Pose3>(firstKey, Pose3(), priorModel)); graphWithPrior.add(PriorFactor<Pose3>(firstKey, Pose3(), priorModel));

View File

@ -43,7 +43,6 @@
#include <gtsam/slam/dataset.h> #include <gtsam/slam/dataset.h>
// Standard headers, added last, so we know headers above work on their own // Standard headers, added last, so we know headers above work on their own
#include <boost/foreach.hpp>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
@ -151,7 +150,7 @@ int main (int argc, char** argv) {
// Loop over odometry // Loop over odometry
gttic_(iSAM); gttic_(iSAM);
BOOST_FOREACH(const TimedOdometry& timedOdometry, odometry) { for(const TimedOdometry& timedOdometry: odometry) {
//--------------------------------- odometry loop ----------------------------------------- //--------------------------------- odometry loop -----------------------------------------
double t; double t;
Pose2 odometry; Pose2 odometry;
@ -196,7 +195,7 @@ int main (int argc, char** argv) {
} }
i += 1; i += 1;
//--------------------------------- odometry loop ----------------------------------------- //--------------------------------- odometry loop -----------------------------------------
} // BOOST_FOREACH } // end for
gttoc_(iSAM); gttoc_(iSAM);
// Print timings // Print timings

View File

@ -78,10 +78,10 @@ int main(int argc, char* argv[]) {
// Simulated measurements from each camera pose, adding them to the factor graph // Simulated measurements from each camera pose, adding them to the factor graph
size_t j = 0; size_t j = 0;
BOOST_FOREACH(const SfM_Track& track, mydata.tracks) { for(const SfM_Track& track: mydata.tracks) {
// Leaf expression for j^th point // Leaf expression for j^th point
Point3_ point_('p', j); Point3_ point_('p', j);
BOOST_FOREACH(const SfM_Measurement& m, track.measurements) { for(const SfM_Measurement& m: track.measurements) {
size_t i = m.first; size_t i = m.first;
Point2 uv = m.second; Point2 uv = m.second;
// Leaf expression for i^th camera // Leaf expression for i^th camera
@ -98,9 +98,9 @@ int main(int argc, char* argv[]) {
Values initial; Values initial;
size_t i = 0; size_t i = 0;
j = 0; j = 0;
BOOST_FOREACH(const SfM_Camera& camera, mydata.cameras) for(const SfM_Camera& camera: mydata.cameras)
initial.insert(C(i++), camera); initial.insert(C(i++), camera);
BOOST_FOREACH(const SfM_Track& track, mydata.tracks) for(const SfM_Track& track: mydata.tracks)
initial.insert(P(j++), track.p); initial.insert(P(j++), track.p);
/* Optimize the graph and print results */ /* Optimize the graph and print results */

View File

@ -55,8 +55,8 @@ int main (int argc, char* argv[]) {
// Add measurements to the factor graph // Add measurements to the factor graph
size_t j = 0; size_t j = 0;
BOOST_FOREACH(const SfM_Track& track, mydata.tracks) { for(const SfM_Track& track: mydata.tracks) {
BOOST_FOREACH(const SfM_Measurement& m, track.measurements) { for(const SfM_Measurement& m: track.measurements) {
size_t i = m.first; size_t i = m.first;
Point2 uv = m.second; Point2 uv = m.second;
graph.push_back(MyFactor(uv, noise, C(i), P(j))); // note use of shorthand symbols C and P graph.push_back(MyFactor(uv, noise, C(i), P(j))); // note use of shorthand symbols C and P
@ -72,8 +72,8 @@ int main (int argc, char* argv[]) {
// Create initial estimate // Create initial estimate
Values initial; Values initial;
size_t i = 0; j = 0; size_t i = 0; j = 0;
BOOST_FOREACH(const SfM_Camera& camera, mydata.cameras) initial.insert(C(i++), camera); for(const SfM_Camera& camera: mydata.cameras) initial.insert(C(i++), camera);
BOOST_FOREACH(const SfM_Track& track, mydata.tracks) initial.insert(P(j++), track.p); for(const SfM_Track& track: mydata.tracks) initial.insert(P(j++), track.p);
/* Optimize the graph and print results */ /* Optimize the graph and print results */
Values result; Values result;

View File

@ -60,8 +60,8 @@ int main (int argc, char* argv[]) {
// Add measurements to the factor graph // Add measurements to the factor graph
size_t j = 0; size_t j = 0;
BOOST_FOREACH(const SfM_Track& track, mydata.tracks) { for(const SfM_Track& track: mydata.tracks) {
BOOST_FOREACH(const SfM_Measurement& m, track.measurements) { for(const SfM_Measurement& m: track.measurements) {
size_t i = m.first; size_t i = m.first;
Point2 uv = m.second; Point2 uv = m.second;
graph.push_back(MyFactor(uv, noise, C(i), P(j))); // note use of shorthand symbols C and P graph.push_back(MyFactor(uv, noise, C(i), P(j))); // note use of shorthand symbols C and P
@ -77,8 +77,8 @@ int main (int argc, char* argv[]) {
// Create initial estimate // Create initial estimate
Values initial; Values initial;
size_t i = 0; j = 0; size_t i = 0; j = 0;
BOOST_FOREACH(const SfM_Camera& camera, mydata.cameras) initial.insert(C(i++), camera); for(const SfM_Camera& camera: mydata.cameras) initial.insert(C(i++), camera);
BOOST_FOREACH(const SfM_Track& track, mydata.tracks) initial.insert(P(j++), track.p); for(const SfM_Track& track: mydata.tracks) initial.insert(P(j++), track.p);
/** --------------- COMPARISON -----------------------**/ /** --------------- COMPARISON -----------------------**/
/** ----------------------------------------------------**/ /** ----------------------------------------------------**/

View File

@ -50,6 +50,7 @@
#include <boost/archive/binary_oarchive.hpp> #include <boost/archive/binary_oarchive.hpp>
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <boost/range/algorithm/set_algorithm.hpp> #include <boost/range/algorithm/set_algorithm.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/random.hpp> #include <boost/random.hpp>
#include <boost/serialization/export.hpp> #include <boost/serialization/export.hpp>
@ -80,7 +81,7 @@ double chi2_red(const gtsam::NonlinearFactorGraph& graph, const gtsam::Values& c
// the factor graph already includes a factor for the prior/equality constraint. // the factor graph already includes a factor for the prior/equality constraint.
// double dof = graph.size() - config.size(); // double dof = graph.size() - config.size();
int graph_dim = 0; int graph_dim = 0;
BOOST_FOREACH(const boost::shared_ptr<gtsam::NonlinearFactor>& nlf, graph) { for(const boost::shared_ptr<gtsam::NonlinearFactor>& nlf: graph) {
graph_dim += (int)nlf->dim(); graph_dim += (int)nlf->dim();
} }
double dof = double(graph_dim) - double(config.dim()); // kaess: changed to dim double dof = double(graph_dim) - double(config.dim()); // kaess: changed to dim
@ -421,9 +422,9 @@ void runIncremental()
//try { //try {
// Marginals marginals(graph, values); // Marginals marginals(graph, values);
// int i=0; // int i=0;
// BOOST_REVERSE_FOREACH(Key key1, values.keys()) { // for (Key key1: boost::adaptors::reverse(values.keys())) {
// int j=0; // int j=0;
// BOOST_REVERSE_FOREACH(Key key2, values.keys()) { // for (Key key12: boost::adaptors::reverse(values.keys())) {
// if(i != j) { // if(i != j) {
// gttic_(jointMarginalInformation); // gttic_(jointMarginalInformation);
// std::vector<Key> keys(2); // std::vector<Key> keys(2);
@ -442,7 +443,7 @@ void runIncremental()
// break; // break;
// } // }
// tictoc_print_(); // tictoc_print_();
// BOOST_FOREACH(Key key, values.keys()) { // for(Key key: values.keys()) {
// gttic_(marginalInformation); // gttic_(marginalInformation);
// Matrix info = marginals.marginalInformation(key); // Matrix info = marginals.marginalInformation(key);
// gttoc_(marginalInformation); // gttoc_(marginalInformation);
@ -535,7 +536,7 @@ void runCompare()
vector<Key> commonKeys; vector<Key> commonKeys;
br::set_intersection(soln1.keys(), soln2.keys(), std::back_inserter(commonKeys)); br::set_intersection(soln1.keys(), soln2.keys(), std::back_inserter(commonKeys));
double maxDiff = 0.0; double maxDiff = 0.0;
BOOST_FOREACH(Key j, commonKeys) for(Key j: commonKeys)
maxDiff = std::max(maxDiff, soln1.at(j).localCoordinates_(soln2.at(j)).norm()); maxDiff = std::max(maxDiff, soln1.at(j).localCoordinates_(soln2.at(j)).norm());
cout << " Maximum solution difference (norm of logmap): " << maxDiff << endl; cout << " Maximum solution difference (norm of logmap): " << maxDiff << endl;
} }
@ -549,7 +550,7 @@ void runPerturb()
// Perturb values // Perturb values
VectorValues noise; VectorValues noise;
BOOST_FOREACH(const Values::KeyValuePair& key_val, initial) for(const Values::KeyValuePair& key_val: initial)
{ {
Vector noisev(key_val.value.dim()); Vector noisev(key_val.value.dim());
for(Vector::Index i = 0; i < noisev.size(); ++i) for(Vector::Index i = 0; i < noisev.size(); ++i)

View File

@ -19,7 +19,6 @@
#include <gtsam/base/Matrix.h> #include <gtsam/base/Matrix.h>
#include <boost/assign/list_of.hpp> #include <boost/assign/list_of.hpp>
#include <boost/foreach.hpp>
#include <map> #include <map>
using namespace std; using namespace std;
@ -76,7 +75,7 @@ map<int, double> testWithoutMemoryAllocation()
const vector<size_t> grainSizes = list_of(1)(10)(100)(1000); const vector<size_t> grainSizes = list_of(1)(10)(100)(1000);
map<int, double> timingResults; map<int, double> timingResults;
BOOST_FOREACH(size_t grainSize, grainSizes) for(size_t grainSize: grainSizes)
{ {
tbb::tick_count t0 = tbb::tick_count::now(); tbb::tick_count t0 = tbb::tick_count::now();
tbb::parallel_for(tbb::blocked_range<size_t>(0, numberOfProblems), WorkerWithoutAllocation(results)); tbb::parallel_for(tbb::blocked_range<size_t>(0, numberOfProblems), WorkerWithoutAllocation(results));
@ -129,7 +128,7 @@ map<int, double> testWithMemoryAllocation()
const vector<size_t> grainSizes = list_of(1)(10)(100)(1000); const vector<size_t> grainSizes = list_of(1)(10)(100)(1000);
map<int, double> timingResults; map<int, double> timingResults;
BOOST_FOREACH(size_t grainSize, grainSizes) for(size_t grainSize: grainSizes)
{ {
tbb::tick_count t0 = tbb::tick_count::now(); tbb::tick_count t0 = tbb::tick_count::now();
tbb::parallel_for(tbb::blocked_range<size_t>(0, numberOfProblems), WorkerWithAllocation(results)); tbb::parallel_for(tbb::blocked_range<size_t>(0, numberOfProblems), WorkerWithAllocation(results));
@ -150,7 +149,7 @@ int main(int argc, char* argv[])
const vector<int> numThreads = list_of(1)(4)(8); const vector<int> numThreads = list_of(1)(4)(8);
Results results; Results results;
BOOST_FOREACH(size_t n, numThreads) for(size_t n: numThreads)
{ {
cout << "With " << n << " threads:" << endl; cout << "With " << n << " threads:" << endl;
tbb::task_scheduler_init init((int)n); tbb::task_scheduler_init init((int)n);
@ -160,19 +159,19 @@ int main(int argc, char* argv[])
} }
cout << "Summary of results:" << endl; cout << "Summary of results:" << endl;
BOOST_FOREACH(const Results::value_type& threads_result, results) for(const Results::value_type& threads_result: results)
{ {
const int threads = threads_result.first; const int threads = threads_result.first;
const ResultWithThreads& result = threads_result.second; const ResultWithThreads& result = threads_result.second;
if(threads != 1) if(threads != 1)
{ {
BOOST_FOREACH(const ResultWithThreads::value_type& grainsize_time, result.grainSizesWithoutAllocation) for(const ResultWithThreads::value_type& grainsize_time: result.grainSizesWithoutAllocation)
{ {
const int grainsize = grainsize_time.first; const int grainsize = grainsize_time.first;
const double speedup = results[1].grainSizesWithoutAllocation[grainsize] / grainsize_time.second; const double speedup = results[1].grainSizesWithoutAllocation[grainsize] / grainsize_time.second;
cout << threads << " threads, without allocation, grain size = " << grainsize << ", speedup = " << speedup << endl; cout << threads << " threads, without allocation, grain size = " << grainsize << ", speedup = " << speedup << endl;
} }
BOOST_FOREACH(const ResultWithThreads::value_type& grainsize_time, result.grainSizesWithAllocation) for(const ResultWithThreads::value_type& grainsize_time: result.grainSizesWithAllocation)
{ {
const int grainsize = grainsize_time.first; const int grainsize = grainsize_time.first;
const double speedup = results[1].grainSizesWithAllocation[grainsize] / grainsize_time.second; const double speedup = results[1].grainSizesWithAllocation[grainsize] / grainsize_time.second;

View File

@ -18,7 +18,6 @@
#include <gtsam/base/DSFVector.h> #include <gtsam/base/DSFVector.h>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/foreach.hpp>
#include <algorithm> #include <algorithm>
using namespace std; using namespace std;
@ -79,7 +78,7 @@ DSFVector::DSFVector(const boost::shared_ptr<V>& v_in,
/* ************************************************************************* */ /* ************************************************************************* */
bool DSFVector::isSingleton(const size_t& label) const { bool DSFVector::isSingleton(const size_t& label) const {
bool result = false; bool result = false;
BOOST_FOREACH(size_t key,keys_) { for(size_t key: keys_) {
if (find(key) == label) { if (find(key) == label) {
if (!result) // find the first occurrence if (!result) // find the first occurrence
result = true; result = true;
@ -93,7 +92,7 @@ bool DSFVector::isSingleton(const size_t& label) const {
/* ************************************************************************* */ /* ************************************************************************* */
std::set<size_t> DSFVector::set(const size_t& label) const { std::set<size_t> DSFVector::set(const size_t& label) const {
std::set < size_t > set; std::set < size_t > set;
BOOST_FOREACH(size_t key,keys_) for(size_t key: keys_)
if (find(key) == label) if (find(key) == label)
set.insert(key); set.insert(key);
return set; return set;
@ -102,7 +101,7 @@ std::set<size_t> DSFVector::set(const size_t& label) const {
/* ************************************************************************* */ /* ************************************************************************* */
std::map<size_t, std::set<size_t> > DSFVector::sets() const { std::map<size_t, std::set<size_t> > DSFVector::sets() const {
std::map<size_t, std::set<size_t> > sets; std::map<size_t, std::set<size_t> > sets;
BOOST_FOREACH(size_t key,keys_) for(size_t key: keys_)
sets[find(key)].insert(key); sets[find(key)].insert(key);
return sets; return sets;
} }
@ -110,7 +109,7 @@ std::map<size_t, std::set<size_t> > DSFVector::sets() const {
/* ************************************************************************* */ /* ************************************************************************* */
std::map<size_t, std::vector<size_t> > DSFVector::arrays() const { std::map<size_t, std::vector<size_t> > DSFVector::arrays() const {
std::map<size_t, std::vector<size_t> > arrays; std::map<size_t, std::vector<size_t> > arrays;
BOOST_FOREACH(size_t key,keys_) for(size_t key: keys_)
arrays[find(key)].push_back(key); arrays[find(key)].push_back(key);
return arrays; return arrays;
} }

View File

@ -23,7 +23,6 @@
#include <Eigen/SVD> #include <Eigen/SVD>
#include <Eigen/LU> #include <Eigen/LU>
#include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include <boost/tokenizer.hpp> #include <boost/tokenizer.hpp>
@ -190,7 +189,7 @@ istream& operator>>(istream& inputStream, Matrix& destinationMatrix) {
// Copy coefficients to matrix // Copy coefficients to matrix
destinationMatrix.resize(height, width); destinationMatrix.resize(height, width);
int row = 0; int row = 0;
BOOST_FOREACH(const vector<double>& rowVec, coeffs) { for(const vector<double>& rowVec: coeffs) {
destinationMatrix.row(row) = Eigen::Map<const Eigen::RowVectorXd>(&rowVec[0], width); destinationMatrix.row(row) = Eigen::Map<const Eigen::RowVectorXd>(&rowVec[0], width);
++ row; ++ row;
} }
@ -419,7 +418,7 @@ Matrix stack(size_t nrMatrices, ...)
Matrix stack(const std::vector<Matrix>& blocks) { Matrix stack(const std::vector<Matrix>& blocks) {
if (blocks.size() == 1) return blocks.at(0); if (blocks.size() == 1) return blocks.at(0);
DenseIndex nrows = 0, ncols = blocks.at(0).cols(); DenseIndex nrows = 0, ncols = blocks.at(0).cols();
BOOST_FOREACH(const Matrix& mat, blocks) { for(const Matrix& mat: blocks) {
nrows += mat.rows(); nrows += mat.rows();
if (ncols != mat.cols()) if (ncols != mat.cols())
throw invalid_argument("Matrix::stack(): column size mismatch!"); throw invalid_argument("Matrix::stack(): column size mismatch!");
@ -427,7 +426,7 @@ Matrix stack(const std::vector<Matrix>& blocks) {
Matrix result(nrows, ncols); Matrix result(nrows, ncols);
DenseIndex cur_row = 0; DenseIndex cur_row = 0;
BOOST_FOREACH(const Matrix& mat, blocks) { for(const Matrix& mat: blocks) {
result.middleRows(cur_row, mat.rows()) = mat; result.middleRows(cur_row, mat.rows()) = mat;
cur_row += mat.rows(); cur_row += mat.rows();
} }
@ -441,7 +440,7 @@ Matrix collect(const std::vector<const Matrix *>& matrices, size_t m, size_t n)
size_t dimA1 = m; size_t dimA1 = m;
size_t dimA2 = n*matrices.size(); size_t dimA2 = n*matrices.size();
if (!m && !n) { if (!m && !n) {
BOOST_FOREACH(const Matrix* M, matrices) { for(const Matrix* M: matrices) {
dimA1 = M->rows(); // TODO: should check if all the same ! dimA1 = M->rows(); // TODO: should check if all the same !
dimA2 += M->cols(); dimA2 += M->cols();
} }
@ -450,7 +449,7 @@ Matrix collect(const std::vector<const Matrix *>& matrices, size_t m, size_t n)
// stl::copy version // stl::copy version
Matrix A(dimA1, dimA2); Matrix A(dimA1, dimA2);
size_t hindex = 0; size_t hindex = 0;
BOOST_FOREACH(const Matrix* M, matrices) { for(const Matrix* M: matrices) {
size_t row_len = M->cols(); size_t row_len = M->cols();
A.block(0, hindex, dimA1, row_len) = *M; A.block(0, hindex, dimA1, row_len) = *M;
hindex += row_len; hindex += row_len;
@ -611,7 +610,7 @@ std::string formatMatrixIndented(const std::string& label, const Matrix& matrix,
boost::tokenizer<boost::char_separator<char> > tok(matrixStr, boost::char_separator<char>("\n")); boost::tokenizer<boost::char_separator<char> > tok(matrixStr, boost::char_separator<char>("\n"));
DenseIndex row = 0; DenseIndex row = 0;
BOOST_FOREACH(const std::string& line, tok) for(const std::string& line: tok)
{ {
assert(row < effectiveRows); assert(row < effectiveRows);
if(row > 0) if(row > 0)

View File

@ -20,7 +20,6 @@
#include <gtsam/base/Testable.h> #include <gtsam/base/Testable.h>
#include <gtsam/global_includes.h> #include <gtsam/global_includes.h>
#include <boost/foreach.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <map> #include <map>
#include <iostream> #include <iostream>
@ -91,7 +90,7 @@ bool assert_equal(const std::vector<V>& expected, const std::vector<V>& actual,
match = false; match = false;
if(match) { if(match) {
size_t i = 0; size_t i = 0;
BOOST_FOREACH(const V& a, expected) { for(const V& a: expected) {
if (!assert_equal(a, actual[i++], tol)) { if (!assert_equal(a, actual[i++], tol)) {
match = false; match = false;
break; break;
@ -100,9 +99,9 @@ bool assert_equal(const std::vector<V>& expected, const std::vector<V>& actual,
} }
if(!match) { if(!match) {
std::cout << "expected: " << std::endl; std::cout << "expected: " << std::endl;
BOOST_FOREACH(const V& a, expected) { std::cout << a << " "; } for(const V& a: expected) { std::cout << a << " "; }
std::cout << "\nactual: " << std::endl; std::cout << "\nactual: " << std::endl;
BOOST_FOREACH(const V& a, actual) { std::cout << a << " "; } for(const V& a: actual) { std::cout << a << " "; }
std::cout << std::endl; std::cout << std::endl;
return false; return false;
} }
@ -133,12 +132,12 @@ bool assert_container_equal(const std::map<V1,V2>& expected, const std::map<V1,V
} }
if(!match) { if(!match) {
std::cout << "expected: " << std::endl; std::cout << "expected: " << std::endl;
BOOST_FOREACH(const typename Map::value_type& a, expected) { for(const typename Map::value_type& a: expected) {
a.first.print("key"); a.first.print("key");
a.second.print(" value"); a.second.print(" value");
} }
std::cout << "\nactual: " << std::endl; std::cout << "\nactual: " << std::endl;
BOOST_FOREACH(const typename Map::value_type& a, actual) { for(const typename Map::value_type& a: actual) {
a.first.print("key"); a.first.print("key");
a.second.print(" value"); a.second.print(" value");
} }
@ -171,12 +170,12 @@ bool assert_container_equal(const std::map<size_t,V2>& expected, const std::map<
} }
if(!match) { if(!match) {
std::cout << "expected: " << std::endl; std::cout << "expected: " << std::endl;
BOOST_FOREACH(const typename Map::value_type& a, expected) { for(const typename Map::value_type& a: expected) {
std::cout << "Key: " << a.first << std::endl; std::cout << "Key: " << a.first << std::endl;
a.second.print(" value"); a.second.print(" value");
} }
std::cout << "\nactual: " << std::endl; std::cout << "\nactual: " << std::endl;
BOOST_FOREACH(const typename Map::value_type& a, actual) { for(const typename Map::value_type& a: actual) {
std::cout << "Key: " << a.first << std::endl; std::cout << "Key: " << a.first << std::endl;
a.second.print(" value"); a.second.print(" value");
} }
@ -210,12 +209,12 @@ bool assert_container_equal(const std::vector<std::pair<V1,V2> >& expected,
} }
if(!match) { if(!match) {
std::cout << "expected: " << std::endl; std::cout << "expected: " << std::endl;
BOOST_FOREACH(const typename VectorPair::value_type& a, expected) { for(const typename VectorPair::value_type& a: expected) {
a.first.print( " first "); a.first.print( " first ");
a.second.print(" second"); a.second.print(" second");
} }
std::cout << "\nactual: " << std::endl; std::cout << "\nactual: " << std::endl;
BOOST_FOREACH(const typename VectorPair::value_type& a, actual) { for(const typename VectorPair::value_type& a: actual) {
a.first.print( " first "); a.first.print( " first ");
a.second.print(" second"); a.second.print(" second");
} }
@ -247,9 +246,9 @@ bool assert_container_equal(const V& expected, const V& actual, double tol = 1e-
} }
if(!match) { if(!match) {
std::cout << "expected: " << std::endl; std::cout << "expected: " << std::endl;
BOOST_FOREACH(const typename V::value_type& a, expected) { a.print(" "); } for(const typename V::value_type& a: expected) { a.print(" "); }
std::cout << "\nactual: " << std::endl; std::cout << "\nactual: " << std::endl;
BOOST_FOREACH(const typename V::value_type& a, actual) { a.print(" "); } for(const typename V::value_type& a: actual) { a.print(" "); }
std::cout << std::endl; std::cout << std::endl;
return false; return false;
} }
@ -279,12 +278,12 @@ bool assert_container_equality(const std::map<size_t,V2>& expected, const std::m
} }
if(!match) { if(!match) {
std::cout << "expected: " << std::endl; std::cout << "expected: " << std::endl;
BOOST_FOREACH(const typename Map::value_type& a, expected) { for(const typename Map::value_type& a: expected) {
std::cout << "Key: " << a.first << std::endl; std::cout << "Key: " << a.first << std::endl;
std::cout << "Value: " << a.second << std::endl; std::cout << "Value: " << a.second << std::endl;
} }
std::cout << "\nactual: " << std::endl; std::cout << "\nactual: " << std::endl;
BOOST_FOREACH(const typename Map::value_type& a, actual) { for(const typename Map::value_type& a: actual) {
std::cout << "Key: " << a.first << std::endl; std::cout << "Key: " << a.first << std::endl;
std::cout << "Value: " << a.second << std::endl; std::cout << "Value: " << a.second << std::endl;
} }
@ -316,9 +315,9 @@ bool assert_container_equality(const V& expected, const V& actual) {
} }
if(!match) { if(!match) {
std::cout << "expected: " << std::endl; std::cout << "expected: " << std::endl;
BOOST_FOREACH(const typename V::value_type& a, expected) { std::cout << a << " "; } for(const typename V::value_type& a: expected) { std::cout << a << " "; }
std::cout << "\nactual: " << std::endl; std::cout << "\nactual: " << std::endl;
BOOST_FOREACH(const typename V::value_type& a, actual) { std::cout << a << " "; } for(const typename V::value_type& a: actual) { std::cout << a << " "; }
std::cout << std::endl; std::cout << std::endl;
return false; return false;
} }

View File

@ -17,7 +17,6 @@
*/ */
#include <gtsam/base/Vector.h> #include <gtsam/base/Vector.h>
#include <boost/foreach.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <stdexcept> #include <stdexcept>
#include <cstdarg> #include <cstdarg>
@ -264,12 +263,12 @@ weightedPseudoinverse(const Vector& a, const Vector& weights) {
Vector concatVectors(const std::list<Vector>& vs) Vector concatVectors(const std::list<Vector>& vs)
{ {
size_t dim = 0; size_t dim = 0;
BOOST_FOREACH(Vector v, vs) for(Vector v: vs)
dim += v.size(); dim += v.size();
Vector A(dim); Vector A(dim);
size_t index = 0; size_t index = 0;
BOOST_FOREACH(Vector v, vs) { for(Vector v: vs) {
for(int d = 0; d < v.size(); d++) for(int d = 0; d < v.size(); d++)
A(d+index) = v(d); A(d+index) = v(d);
index += v.size(); index += v.size();

View File

@ -20,7 +20,6 @@
#include <CppUnitLite/TestHarness.h> #include <CppUnitLite/TestHarness.h>
#include <boost/foreach.hpp>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/assign/std/list.hpp> #include <boost/assign/std/list.hpp>
#include <boost/assign/std/set.hpp> #include <boost/assign/std/set.hpp>
@ -70,7 +69,7 @@ TEST(DSFBase, mergePairwiseMatches) {
// Merge matches // Merge matches
DSFBase dsf(7); // We allow for keys 0..6 DSFBase dsf(7); // We allow for keys 0..6
BOOST_FOREACH(const Match& m, matches) for(const Match& m: matches)
dsf.merge(m.first,m.second); dsf.merge(m.first,m.second);
// Each point is now associated with a set, represented by one of its members // Each point is now associated with a set, represented by one of its members
@ -206,7 +205,7 @@ TEST(DSFVector, mergePairwiseMatches) {
// Merge matches // Merge matches
DSFVector dsf(keys); DSFVector dsf(keys);
BOOST_FOREACH(const Match& m, matches) for(const Match& m: matches)
dsf.merge(m.first,m.second); dsf.merge(m.first,m.second);
// Check that we have two connected components, 1,2,3 and 4,5,6 // Check that we have two connected components, 1,2,3 and 4,5,6

View File

@ -19,7 +19,6 @@
#include <gtsam/base/Testable.h> #include <gtsam/base/Testable.h>
#include <Eigen/Core> #include <Eigen/Core>
#include <iostream> #include <iostream>
#include <boost/foreach.hpp>
namespace gtsam { namespace gtsam {

View File

@ -21,7 +21,6 @@
#include <gtsam/base/testLie.h> #include <gtsam/base/testLie.h>
#include <CppUnitLite/TestHarness.h> #include <CppUnitLite/TestHarness.h>
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@ -907,10 +906,6 @@ TEST(Matrix, weighted_elimination )
Vector d = (Vector(4) << 0.2, -0.14, 0.0, 0.2).finished(); Vector d = (Vector(4) << 0.2, -0.14, 0.0, 0.2).finished();
Vector newSigmas = (Vector(4) << 0.0894427, 0.0894427, 0.223607, 0.223607).finished(); Vector newSigmas = (Vector(4) << 0.0894427, 0.0894427, 0.223607, 0.223607).finished();
Vector r;
double di, sigma;
size_t i;
// perform elimination // perform elimination
Matrix A1 = A; Matrix A1 = A;
Vector b1 = b; Vector b1 = b;
@ -918,8 +913,11 @@ TEST(Matrix, weighted_elimination )
weighted_eliminate(A1, b1, sigmas); weighted_eliminate(A1, b1, sigmas);
// unpack and verify // unpack and verify
i = 0; size_t i = 0;
BOOST_FOREACH(boost::tie(r, di, sigma), solution){ for (const auto& tuple : solution) {
Vector r;
double di, sigma;
boost::tie(r, di, sigma) = tuple;
EXPECT(assert_equal(r, expectedR.row(i))); // verify r EXPECT(assert_equal(r, expectedR.row(i))); // verify r
DOUBLES_EQUAL(d(i), di, 1e-8); // verify d DOUBLES_EQUAL(d(i), di, 1e-8); // verify d
DOUBLES_EQUAL(newSigmas(i), sigma, 1e-5); // verify sigma DOUBLES_EQUAL(newSigmas(i), sigma, 1e-5); // verify sigma

View File

@ -20,7 +20,6 @@
#include <gtsam/base/timing.h> #include <gtsam/base/timing.h>
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
#include <boost/foreach.hpp>
#include <boost/format.hpp> #include <boost/format.hpp>
#include <cmath> #include <cmath>
@ -66,7 +65,7 @@ TimingOutline::TimingOutline(const std::string& label, size_t id) :
size_t TimingOutline::time() const { size_t TimingOutline::time() const {
size_t time = 0; size_t time = 0;
bool hasChildren = false; bool hasChildren = false;
BOOST_FOREACH(const ChildMap::value_type& child, children_) { for(const ChildMap::value_type& child: children_) {
time += child.second->time(); time += child.second->time();
hasChildren = true; hasChildren = true;
} }
@ -86,11 +85,11 @@ void TimingOutline::print(const std::string& outline) const {
// Order children // Order children
typedef FastMap<size_t, boost::shared_ptr<TimingOutline> > ChildOrder; typedef FastMap<size_t, boost::shared_ptr<TimingOutline> > ChildOrder;
ChildOrder childOrder; ChildOrder childOrder;
BOOST_FOREACH(const ChildMap::value_type& child, children_) { for(const ChildMap::value_type& child: children_) {
childOrder[child.second->myOrder_] = child.second; childOrder[child.second->myOrder_] = child.second;
} }
// Print children // Print children
BOOST_FOREACH(const ChildOrder::value_type order_child, childOrder) { for(const ChildOrder::value_type order_child: childOrder) {
std::string childOutline(outline); std::string childOutline(outline);
childOutline += "| "; childOutline += "| ";
order_child.second->print(childOutline); order_child.second->print(childOutline);
@ -130,7 +129,7 @@ void TimingOutline::print2(const std::string& outline,
std::cout << std::endl; std::cout << std::endl;
} }
BOOST_FOREACH(const ChildMap::value_type& child, children_) { for(const ChildMap::value_type& child: children_) {
std::string childOutline(outline); std::string childOutline(outline);
if (n_ == 0) { if (n_ == 0) {
child.second->print2(childOutline, childTotal); child.second->print2(childOutline, childTotal);
@ -210,7 +209,7 @@ void TimingOutline::finishedIteration() {
if (tMin_ == 0 || tIt_ < tMin_) if (tMin_ == 0 || tIt_ < tMin_)
tMin_ = tIt_; tMin_ = tIt_;
tIt_ = 0; tIt_ = 0;
BOOST_FOREACH(ChildMap::value_type& child, children_) { for(ChildMap::value_type& child: children_) {
child.second->finishedIteration(); child.second->finishedIteration();
} }
} }

View File

@ -29,7 +29,6 @@
#include <string> #include <string>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/foreach.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
namespace gtsam { namespace gtsam {
@ -91,7 +90,7 @@ void DepthFirstForest(FOREST& forest, DATA& rootData, VISITOR_PRE& visitorPre,
// Add roots to stack (insert such that they are visited and processed in order // Add roots to stack (insert such that they are visited and processed in order
{ {
typename Stack::iterator insertLocation = stack.begin(); typename Stack::iterator insertLocation = stack.begin();
BOOST_FOREACH(const sharedNode& root, forest.roots()) for(const sharedNode& root: forest.roots())
stack.insert(insertLocation, TraversalNode(root, rootData)); stack.insert(insertLocation, TraversalNode(root, rootData));
} }
@ -112,7 +111,7 @@ void DepthFirstForest(FOREST& forest, DATA& rootData, VISITOR_PRE& visitorPre,
node.dataPointer = dataList.insert(dataList.end(), node.dataPointer = dataList.insert(dataList.end(),
visitorPre(node.treeNode, node.parentData)); visitorPre(node.treeNode, node.parentData));
typename Stack::iterator insertLocation = stack.begin(); typename Stack::iterator insertLocation = stack.begin();
BOOST_FOREACH(const sharedNode& child, node.treeNode->children) for(const sharedNode& child: node.treeNode->children)
stack.insert(insertLocation, TraversalNode(child, *node.dataPointer)); stack.insert(insertLocation, TraversalNode(child, *node.dataPointer));
node.expanded = true; node.expanded = true;
} }

View File

@ -20,7 +20,6 @@
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/foreach.hpp>
#ifdef GTSAM_USE_TBB #ifdef GTSAM_USE_TBB
# include <tbb/tbb.h> # include <tbb/tbb.h>
@ -101,7 +100,7 @@ namespace gtsam {
tbb::task* firstChild = 0; tbb::task* firstChild = 0;
tbb::task_list childTasks; tbb::task_list childTasks;
BOOST_FOREACH(const boost::shared_ptr<NODE>& child, treeNode->children) for(const boost::shared_ptr<NODE>& child: treeNode->children)
{ {
// Process child in a subtask. Important: Run visitorPre before calling // Process child in a subtask. Important: Run visitorPre before calling
// allocate_child so that if visitorPre throws an exception, we will not have // allocate_child so that if visitorPre throws an exception, we will not have
@ -143,7 +142,7 @@ namespace gtsam {
void processNodeRecursively(const boost::shared_ptr<NODE>& node, DATA& myData) void processNodeRecursively(const boost::shared_ptr<NODE>& node, DATA& myData)
{ {
BOOST_FOREACH(const boost::shared_ptr<NODE>& child, node->children) for(const boost::shared_ptr<NODE>& child: node->children)
{ {
DATA childData = visitorPre(child, myData); DATA childData = visitorPre(child, myData);
processNodeRecursively(child, childData); processNodeRecursively(child, childData);
@ -174,7 +173,7 @@ namespace gtsam {
typedef PreOrderTask<NODE, DATA, VISITOR_PRE, VISITOR_POST> PreOrderTask; typedef PreOrderTask<NODE, DATA, VISITOR_PRE, VISITOR_POST> PreOrderTask;
// Create data and tasks for our children // Create data and tasks for our children
tbb::task_list tasks; tbb::task_list tasks;
BOOST_FOREACH(const boost::shared_ptr<NODE>& root, roots) for(const boost::shared_ptr<NODE>& root: roots)
{ {
boost::shared_ptr<DATA> rootData = boost::allocate_shared<DATA>(tbb::scalable_allocator<DATA>(), visitorPre(root, myData)); boost::shared_ptr<DATA> rootData = boost::allocate_shared<DATA>(tbb::scalable_allocator<DATA>(), visitorPre(root, myData));
tasks.push_back(*new(allocate_child()) tasks.push_back(*new(allocate_child())

View File

@ -63,7 +63,7 @@ namespace gtsam {
{ {
int largestProblemSize = 0; int largestProblemSize = 0;
int secondLargestProblemSize = 0; int secondLargestProblemSize = 0;
BOOST_FOREACH(const boost::shared_ptr<NODE>& child, node->children) for(const boost::shared_ptr<NODE>& child: node->children)
{ {
if (child->problemSize() > largestProblemSize) if (child->problemSize() > largestProblemSize)
{ {

View File

@ -18,7 +18,6 @@
#pragma once #pragma once
#include <boost/foreach.hpp>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <map> #include <map>
@ -36,7 +35,7 @@ namespace gtsam {
public: public:
void print(const std::string& s = "Assignment: ") const { void print(const std::string& s = "Assignment: ") const {
std::cout << s << ": "; std::cout << s << ": ";
BOOST_FOREACH(const typename Assignment::value_type& keyValue, *this) for(const typename Assignment::value_type& keyValue: *this)
std::cout << "(" << keyValue.first << ", " << keyValue.second << ")"; std::cout << "(" << keyValue.first << ", " << keyValue.second << ")";
std::cout << std::endl; std::cout << std::endl;
} }
@ -65,7 +64,7 @@ namespace gtsam {
std::vector<Assignment<L> > allPossValues; std::vector<Assignment<L> > allPossValues;
Assignment<L> values; Assignment<L> values;
typedef std::pair<L, size_t> DiscreteKey; typedef std::pair<L, size_t> DiscreteKey;
BOOST_FOREACH(const DiscreteKey& key, keys) for(const DiscreteKey& key: keys)
values[key.first] = 0; //Initialize from 0 values[key.first] = 0; //Initialize from 0
while (1) { while (1) {
allPossValues.push_back(values); allPossValues.push_back(values);

View File

@ -24,7 +24,6 @@
#include <boost/format.hpp> #include <boost/format.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include <boost/assign/std/vector.hpp> #include <boost/assign/std/vector.hpp>
using boost::assign::operator+=; using boost::assign::operator+=;
@ -310,7 +309,7 @@ namespace gtsam {
label_(label), allSame_(true) { label_(label), allSame_(true) {
branches_.reserve(f.branches_.size()); // reserve space branches_.reserve(f.branches_.size()); // reserve space
BOOST_FOREACH (const NodePtr& branch, f.branches_) for (const NodePtr& branch: f.branches_)
push_back(branch->apply(op)); push_back(branch->apply(op));
} }
@ -332,7 +331,7 @@ namespace gtsam {
// If second argument of binary op is Leaf node, recurse on branches // If second argument of binary op is Leaf node, recurse on branches
NodePtr apply_g_op_fL(const Leaf& fL, const Binary& op) const { NodePtr apply_g_op_fL(const Leaf& fL, const Binary& op) const {
boost::shared_ptr<Choice> h(new Choice(label(), nrChoices())); boost::shared_ptr<Choice> h(new Choice(label(), nrChoices()));
BOOST_FOREACH(NodePtr branch, branches_) for(NodePtr branch: branches_)
h->push_back(fL.apply_f_op_g(*branch, op)); h->push_back(fL.apply_f_op_g(*branch, op));
return Unique(h); return Unique(h);
} }
@ -347,7 +346,7 @@ namespace gtsam {
template<typename OP> template<typename OP>
NodePtr apply_fC_op_gL(const Leaf& gL, OP op) const { NodePtr apply_fC_op_gL(const Leaf& gL, OP op) const {
boost::shared_ptr<Choice> h(new Choice(label(), nrChoices())); boost::shared_ptr<Choice> h(new Choice(label(), nrChoices()));
BOOST_FOREACH(const NodePtr& branch, branches_) for(const NodePtr& branch: branches_)
h->push_back(branch->apply_f_op_g(gL, op)); h->push_back(branch->apply_f_op_g(gL, op));
return Unique(h); return Unique(h);
} }
@ -359,7 +358,7 @@ namespace gtsam {
// second case, not label of interest, just recurse // second case, not label of interest, just recurse
boost::shared_ptr<Choice> r(new Choice(label_, branches_.size())); boost::shared_ptr<Choice> r(new Choice(label_, branches_.size()));
BOOST_FOREACH(const NodePtr& branch, branches_) for(const NodePtr& branch: branches_)
r->push_back(branch->choose(label, index)); r->push_back(branch->choose(label, index));
return Unique(r); return Unique(r);
} }
@ -593,7 +592,7 @@ namespace gtsam {
// put together via Shannon expansion otherwise not sorted. // put together via Shannon expansion otherwise not sorted.
std::vector<LY> functions; std::vector<LY> functions;
BOOST_FOREACH(const MXNodePtr& branch, choice->branches()) { for(const MXNodePtr& branch: choice->branches()) {
LY converted(convert<M, X>(branch, map, op)); LY converted(convert<M, X>(branch, map, op));
functions += converted; functions += converted;
} }

View File

@ -21,7 +21,6 @@
#include <gtsam/discrete/DiscreteConditional.h> #include <gtsam/discrete/DiscreteConditional.h>
#include <gtsam/base/FastSet.h> #include <gtsam/base/FastSet.h>
#include <boost/foreach.hpp>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
using namespace std; using namespace std;
@ -66,11 +65,11 @@ namespace gtsam {
ADT::Binary op) const { ADT::Binary op) const {
map<Key,size_t> cs; // new cardinalities map<Key,size_t> cs; // new cardinalities
// make unique key-cardinality map // make unique key-cardinality map
BOOST_FOREACH(Key j, keys()) cs[j] = cardinality(j); for(Key j: keys()) cs[j] = cardinality(j);
BOOST_FOREACH(Key j, f.keys()) cs[j] = f.cardinality(j); for(Key j: f.keys()) cs[j] = f.cardinality(j);
// Convert map into keys // Convert map into keys
DiscreteKeys keys; DiscreteKeys keys;
BOOST_FOREACH(const DiscreteKey& key, cs) for(const DiscreteKey& key: cs)
keys.push_back(key); keys.push_back(key);
// apply operand // apply operand
ADT result = ADT::apply(f, op); ADT result = ADT::apply(f, op);

View File

@ -22,7 +22,6 @@
#include <gtsam/discrete/Potentials.h> #include <gtsam/discrete/Potentials.h>
#include <gtsam/inference/Ordering.h> #include <gtsam/inference/Ordering.h>
#include <boost/foreach.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <vector> #include <vector>

View File

@ -19,7 +19,9 @@
#include <gtsam/discrete/DiscreteBayesNet.h> #include <gtsam/discrete/DiscreteBayesNet.h>
#include <gtsam/discrete/DiscreteConditional.h> #include <gtsam/discrete/DiscreteConditional.h>
#include <gtsam/inference/FactorGraph-inst.h> #include <gtsam/inference/FactorGraph-inst.h>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/range/adaptor/reversed.hpp>
namespace gtsam { namespace gtsam {
@ -46,7 +48,7 @@ namespace gtsam {
double DiscreteBayesNet::evaluate(const DiscreteConditional::Values & values) const { double DiscreteBayesNet::evaluate(const DiscreteConditional::Values & values) const {
// evaluate all conditionals and multiply // evaluate all conditionals and multiply
double result = 1.0; double result = 1.0;
BOOST_FOREACH(DiscreteConditional::shared_ptr conditional, *this) for(DiscreteConditional::shared_ptr conditional: *this)
result *= (*conditional)(values); result *= (*conditional)(values);
return result; return result;
} }
@ -55,7 +57,7 @@ namespace gtsam {
DiscreteFactor::sharedValues DiscreteBayesNet::optimize() const { DiscreteFactor::sharedValues DiscreteBayesNet::optimize() const {
// solve each node in turn in topological sort order (parents first) // solve each node in turn in topological sort order (parents first)
DiscreteFactor::sharedValues result(new DiscreteFactor::Values()); DiscreteFactor::sharedValues result(new DiscreteFactor::Values());
BOOST_REVERSE_FOREACH (DiscreteConditional::shared_ptr conditional, *this) for (auto conditional: boost::adaptors::reverse(*this))
conditional->solveInPlace(*result); conditional->solveInPlace(*result);
return result; return result;
} }
@ -64,7 +66,7 @@ namespace gtsam {
DiscreteFactor::sharedValues DiscreteBayesNet::sample() const { DiscreteFactor::sharedValues DiscreteBayesNet::sample() const {
// sample each node in turn in topological sort order (parents first) // sample each node in turn in topological sort order (parents first)
DiscreteFactor::sharedValues result(new DiscreteFactor::Values()); DiscreteFactor::sharedValues result(new DiscreteFactor::Values());
BOOST_REVERSE_FOREACH(DiscreteConditional::shared_ptr conditional, *this) for (auto conditional: boost::adaptors::reverse(*this))
conditional->sampleInPlace(*result); conditional->sampleInPlace(*result);
return result; return result;
} }

View File

@ -87,7 +87,7 @@ bool DiscreteConditional::equals(const DiscreteFactor& other,
Potentials::ADT DiscreteConditional::choose(const Values& parentsValues) const { Potentials::ADT DiscreteConditional::choose(const Values& parentsValues) const {
ADT pFS(*this); ADT pFS(*this);
Key j; size_t value; Key j; size_t value;
BOOST_FOREACH(Key key, parents()) for(Key key: parents())
try { try {
j = (key); j = (key);
value = parentsValues.at(j); value = parentsValues.at(j);
@ -111,7 +111,7 @@ void DiscreteConditional::solveInPlace(Values& values) const {
double maxP = 0; double maxP = 0;
DiscreteKeys keys; DiscreteKeys keys;
BOOST_FOREACH(Key idx, frontals()) { for(Key idx: frontals()) {
DiscreteKey dk(idx, cardinality(idx)); DiscreteKey dk(idx, cardinality(idx));
keys & dk; keys & dk;
} }
@ -119,7 +119,7 @@ void DiscreteConditional::solveInPlace(Values& values) const {
vector<Values> allPosbValues = cartesianProduct(keys); vector<Values> allPosbValues = cartesianProduct(keys);
// Find the MPE // Find the MPE
BOOST_FOREACH(Values& frontalVals, allPosbValues) { for(Values& frontalVals: allPosbValues) {
double pValueS = pFS(frontalVals); // P(F=value|S=parentsValues) double pValueS = pFS(frontalVals); // P(F=value|S=parentsValues)
// Update MPE solution if better // Update MPE solution if better
if (pValueS > maxP) { if (pValueS > maxP) {
@ -129,7 +129,7 @@ void DiscreteConditional::solveInPlace(Values& values) const {
} }
//set values (inPlace) to mpe //set values (inPlace) to mpe
BOOST_FOREACH(Key j, frontals()) { for(Key j: frontals()) {
values[j] = mpe[j]; values[j] = mpe[j];
} }
} }

View File

@ -18,7 +18,6 @@
*/ */
#include <gtsam/discrete/DiscreteFactor.h> #include <gtsam/discrete/DiscreteFactor.h>
#include <boost/foreach.hpp>
using namespace std; using namespace std;

View File

@ -41,7 +41,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
KeySet DiscreteFactorGraph::keys() const { KeySet DiscreteFactorGraph::keys() const {
KeySet keys; KeySet keys;
BOOST_FOREACH(const sharedFactor& factor, *this) for(const sharedFactor& factor: *this)
if (factor) keys.insert(factor->begin(), factor->end()); if (factor) keys.insert(factor->begin(), factor->end());
return keys; return keys;
} }
@ -49,7 +49,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
DecisionTreeFactor DiscreteFactorGraph::product() const { DecisionTreeFactor DiscreteFactorGraph::product() const {
DecisionTreeFactor result; DecisionTreeFactor result;
BOOST_FOREACH(const sharedFactor& factor, *this) for(const sharedFactor& factor: *this)
if (factor) result = (*factor) * result; if (factor) result = (*factor) * result;
return result; return result;
} }
@ -58,7 +58,7 @@ namespace gtsam {
double DiscreteFactorGraph::operator()( double DiscreteFactorGraph::operator()(
const DiscreteFactor::Values &values) const { const DiscreteFactor::Values &values) const {
double product = 1.0; double product = 1.0;
BOOST_FOREACH( const sharedFactor& factor, factors_ ) for( const sharedFactor& factor: factors_ )
product *= (*factor)(values); product *= (*factor)(values);
return product; return product;
} }
@ -78,7 +78,7 @@ namespace gtsam {
// /* ************************************************************************* */ // /* ************************************************************************* */
// void DiscreteFactorGraph::permuteWithInverse( // void DiscreteFactorGraph::permuteWithInverse(
// const Permutation& inversePermutation) { // const Permutation& inversePermutation) {
// BOOST_FOREACH(const sharedFactor& factor, factors_) { // for(const sharedFactor& factor: factors_) {
// if(factor) // if(factor)
// factor->permuteWithInverse(inversePermutation); // factor->permuteWithInverse(inversePermutation);
// } // }
@ -87,7 +87,7 @@ namespace gtsam {
// /* ************************************************************************* */ // /* ************************************************************************* */
// void DiscreteFactorGraph::reduceWithInverse( // void DiscreteFactorGraph::reduceWithInverse(
// const internal::Reduction& inverseReduction) { // const internal::Reduction& inverseReduction) {
// BOOST_FOREACH(const sharedFactor& factor, factors_) { // for(const sharedFactor& factor: factors_) {
// if(factor) // if(factor)
// factor->reduceWithInverse(inverseReduction); // factor->reduceWithInverse(inverseReduction);
// } // }
@ -107,7 +107,7 @@ namespace gtsam {
// PRODUCT: multiply all factors // PRODUCT: multiply all factors
gttic(product); gttic(product);
DecisionTreeFactor product; DecisionTreeFactor product;
BOOST_FOREACH(const DiscreteFactor::shared_ptr& factor, factors) for(const DiscreteFactor::shared_ptr& factor: factors)
product = (*factor) * product; product = (*factor) * product;
gttoc(product); gttoc(product);

View File

@ -18,7 +18,6 @@
#include <iostream> #include <iostream>
#include <boost/format.hpp> // for key names #include <boost/format.hpp> // for key names
#include <boost/foreach.hpp> // FOREACH
#include "DiscreteKey.h" #include "DiscreteKey.h"
namespace gtsam { namespace gtsam {
@ -34,7 +33,7 @@ namespace gtsam {
vector<Key> DiscreteKeys::indices() const { vector<Key> DiscreteKeys::indices() const {
vector < Key > js; vector < Key > js;
BOOST_FOREACH(const DiscreteKey& key, *this) for(const DiscreteKey& key: *this)
js.push_back(key.first); js.push_back(key.first);
return js; return js;
} }
@ -42,7 +41,7 @@ namespace gtsam {
map<Key,size_t> DiscreteKeys::cardinalities() const { map<Key,size_t> DiscreteKeys::cardinalities() const {
map<Key,size_t> cs; map<Key,size_t> cs;
cs.insert(begin(),end()); cs.insert(begin(),end());
// BOOST_FOREACH(const DiscreteKey& key, *this) // for(const DiscreteKey& key: *this)
// cs.insert(key); // cs.insert(key);
return cs; return cs;
} }

View File

@ -54,7 +54,7 @@ namespace gtsam {
void Potentials::print(const string& s, void Potentials::print(const string& s,
const KeyFormatter& formatter) const { const KeyFormatter& formatter) const {
cout << s << "\n Cardinalities: "; cout << s << "\n Cardinalities: ";
BOOST_FOREACH(const DiscreteKey& key, cardinalities_) for(const DiscreteKey& key: cardinalities_)
cout << formatter(key.first) << "=" << formatter(key.second) << " "; cout << formatter(key.first) << "=" << formatter(key.second) << " ";
cout << endl; cout << endl;
ADT::print(" "); ADT::print(" ");
@ -68,11 +68,11 @@ namespace gtsam {
// map<Key, Key> ordering; // map<Key, Key> ordering;
// //
// // Get the original keys from cardinalities_ // // Get the original keys from cardinalities_
// BOOST_FOREACH(const DiscreteKey& key, cardinalities_) // for(const DiscreteKey& key: cardinalities_)
// keys & key; // keys & key;
// //
// // Perform Permutation // // Perform Permutation
// BOOST_FOREACH(DiscreteKey& key, keys) { // for(DiscreteKey& key: keys) {
// ordering[key.first] = remapping[key.first]; // ordering[key.first] = remapping[key.first];
// key.first = ordering[key.first]; // key.first = ordering[key.first];
// } // }

View File

@ -17,7 +17,6 @@
*/ */
#include <sstream> #include <sstream>
#include <boost/foreach.hpp>
#include "Signature.h" #include "Signature.h"
@ -125,7 +124,7 @@ namespace gtsam {
DiscreteKeys Signature::discreteKeysParentsFirst() const { DiscreteKeys Signature::discreteKeysParentsFirst() const {
DiscreteKeys keys; DiscreteKeys keys;
BOOST_FOREACH(const DiscreteKey& key, parents_) for(const DiscreteKey& key: parents_)
keys.push_back(key); keys.push_back(key);
keys.push_back(key_); keys.push_back(key_);
return keys; return keys;
@ -134,7 +133,7 @@ namespace gtsam {
vector<Key> Signature::indices() const { vector<Key> Signature::indices() const {
vector<Key> js; vector<Key> js;
js.push_back(key_.first); js.push_back(key_.first);
BOOST_FOREACH(const DiscreteKey& key, parents_) for(const DiscreteKey& key: parents_)
js.push_back(key.first); js.push_back(key.first);
return js; return js;
} }
@ -142,8 +141,8 @@ namespace gtsam {
vector<double> Signature::cpt() const { vector<double> Signature::cpt() const {
vector<double> cpt; vector<double> cpt;
if (table_) { if (table_) {
BOOST_FOREACH(const Row& row, *table_) for(const Row& row: *table_)
BOOST_FOREACH(const double& x, row) for(const double& x: row)
cpt.push_back(x); cpt.push_back(x);
} }
return cpt; return cpt;
@ -171,7 +170,7 @@ namespace gtsam {
// qi::phrase_parse(f, l, parser::grammar.table, qi::space, table); // using full grammar // qi::phrase_parse(f, l, parser::grammar.table, qi::space, table); // using full grammar
parser::parse_table(spec, table); parser::parse_table(spec, table);
if (success) { if (success) {
BOOST_FOREACH(Row& row, table) for(Row& row: table)
normalize(row); normalize(row);
table_.reset(table); table_.reset(table);
} }
@ -180,7 +179,7 @@ namespace gtsam {
Signature& Signature::operator=(const Table& t) { Signature& Signature::operator=(const Table& t) {
Table table = t; Table table = t;
BOOST_FOREACH(Row& row, table) for(Row& row: table)
normalize(row); normalize(row);
table_.reset(table); table_.reset(table);
return *this; return *this;

View File

@ -25,7 +25,6 @@
#define DISABLE_TIMING #define DISABLE_TIMING
#include <boost/timer.hpp> #include <boost/timer.hpp>
#include <boost/foreach.hpp>
#include <boost/tokenizer.hpp> #include <boost/tokenizer.hpp>
#include <boost/assign/std/map.hpp> #include <boost/assign/std/map.hpp>
#include <boost/assign/std/vector.hpp> #include <boost/assign/std/vector.hpp>
@ -66,7 +65,7 @@ void dot(const T&f, const string& filename) {
typename DecisionTree<L, double>::Node::Ptr DecisionTree<L, double>::Choice::apply_fC_op_gL( typename DecisionTree<L, double>::Node::Ptr DecisionTree<L, double>::Choice::apply_fC_op_gL(
Cache& cache, const Leaf& gL, Mul op) const { Cache& cache, const Leaf& gL, Mul op) const {
Ptr h(new Choice(label(), cardinality())); Ptr h(new Choice(label(), cardinality()));
BOOST_FOREACH(const NodePtr& branch, branches_) for(const NodePtr& branch: branches_)
h->push_back(branch->apply_f_op_g(cache, gL, op)); h->push_back(branch->apply_f_op_g(cache, gL, op));
return Unique(cache, h); return Unique(cache, h);
} }
@ -401,7 +400,7 @@ TEST(ADT, constructor)
DiscreteKey z0(0,5), z1(1,4), z2(2,3), z3(3,2); DiscreteKey z0(0,5), z1(1,4), z2(2,3), z3(3,2);
vector<double> table(5 * 4 * 3 * 2); vector<double> table(5 * 4 * 3 * 2);
double x = 0; double x = 0;
BOOST_FOREACH(double& t, table) for(double& t: table)
t = x++; t = x++;
ADT f3(z0 & z1 & z2 & z3, table); ADT f3(z0 & z1 & z2 & z3, table);
Assignment<Key> assignment; Assignment<Key> assignment;

View File

@ -63,7 +63,7 @@
//// double evaluate(const DiscreteConditional::Values & values) { //// double evaluate(const DiscreteConditional::Values & values) {
//// double result = (*(this->conditional_))(values); //// double result = (*(this->conditional_))(values);
//// // evaluate all children and multiply into result //// // evaluate all children and multiply into result
//// BOOST_FOREACH(boost::shared_ptr<Clique> c, children_) //// for(boost::shared_ptr<Clique> c: children_)
//// result *= c->evaluate(values); //// result *= c->evaluate(values);
//// return result; //// return result;
//// } //// }
@ -213,7 +213,7 @@
// //
// // calculate all shortcuts to root // // calculate all shortcuts to root
// DiscreteBayesTree::Nodes cliques = bayesTree.nodes(); // DiscreteBayesTree::Nodes cliques = bayesTree.nodes();
// BOOST_FOREACH(Clique::shared_ptr c, cliques) { // for(Clique::shared_ptr c: cliques) {
// DiscreteBayesNet shortcut = c->shortcut(R, EliminateDiscrete); // DiscreteBayesNet shortcut = c->shortcut(R, EliminateDiscrete);
// if (debug) { // if (debug) {
// c->printSignature(); // c->printSignature();

View File

@ -321,7 +321,7 @@ struct Graph2: public std::list<Factor2> {
/** Add a factor graph*/ /** Add a factor graph*/
// void operator +=(const Graph2& graph) { // void operator +=(const Graph2& graph) {
// BOOST_FOREACH(const Factor2& f, graph) // for(const Factor2& f: graph)
// push_back(f); // push_back(f);
// } // }
friend std::ostream& operator <<(std::ostream &os, const Graph2& graph); friend std::ostream& operator <<(std::ostream &os, const Graph2& graph);
@ -334,7 +334,7 @@ friend std::ostream& operator <<(std::ostream &os, const Graph2& graph);
// return graph; // return graph;
//} //}
std::ostream& operator <<(std::ostream &os, const Graph2& graph) { std::ostream& operator <<(std::ostream &os, const Graph2& graph) {
BOOST_FOREACH(const Factor2& f, graph) for(const Factor2& f: graph)
os << f << endl; os << f << endl;
return os; return os;
} }

View File

@ -20,7 +20,6 @@
#include <gtsam/geometry/CameraSet.h> #include <gtsam/geometry/CameraSet.h>
#include <gtsam/geometry/triangulation.h> #include <gtsam/geometry/triangulation.h>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/foreach.hpp>
namespace gtsam { namespace gtsam {

View File

@ -16,7 +16,6 @@
*/ */
#include <gtsam/geometry/Point2.h> #include <gtsam/geometry/Point2.h>
#include <boost/foreach.hpp>
#include <cmath> #include <cmath>
using namespace std; using namespace std;

View File

@ -19,8 +19,6 @@
#include <gtsam/base/Testable.h> #include <gtsam/base/Testable.h>
#include <gtsam/base/concepts.h> #include <gtsam/base/concepts.h>
#include <boost/foreach.hpp>
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
@ -314,7 +312,7 @@ boost::optional<Pose2> align(const vector<Point2Pair>& pairs) {
// calculate centroids // calculate centroids
Point2 cp,cq; Point2 cp,cq;
BOOST_FOREACH(const Point2Pair& pair, pairs) { for(const Point2Pair& pair: pairs) {
cp += pair.first; cp += pair.first;
cq += pair.second; cq += pair.second;
} }
@ -323,7 +321,7 @@ boost::optional<Pose2> align(const vector<Point2Pair>& pairs) {
// calculate cos and sin // calculate cos and sin
double c=0,s=0; double c=0,s=0;
BOOST_FOREACH(const Point2Pair& pair, pairs) { for(const Point2Pair& pair: pairs) {
Point2 dq = pair.first - cp; Point2 dq = pair.first - cp;
Point2 dp = pair.second - cq; Point2 dp = pair.second - cq;
c += dp.x() * dq.x() + dp.y() * dq.y(); c += dp.x() * dq.x() + dp.y() * dq.y();

View File

@ -19,7 +19,6 @@
#include <gtsam/geometry/concepts.h> #include <gtsam/geometry/concepts.h>
#include <gtsam/base/concepts.h> #include <gtsam/base/concepts.h>
#include <boost/foreach.hpp>
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
@ -424,7 +423,7 @@ boost::optional<Pose3> Pose3::Align(const std::vector<Point3Pair>& abPointPairs)
boost::optional<Pose3> align(const vector<Point3Pair>& baPointPairs) { boost::optional<Pose3> align(const vector<Point3Pair>& baPointPairs) {
vector<Point3Pair> abPointPairs; vector<Point3Pair> abPointPairs;
BOOST_FOREACH (const Point3Pair& baPair, baPointPairs) { for (const Point3Pair& baPair: baPointPairs) {
abPointPairs.push_back(make_pair(baPair.second, baPair.first)); abPointPairs.push_back(make_pair(baPair.second, baPair.first));
} }
return Pose3::Align(abPointPairs); return Pose3::Align(abPointPairs);

View File

@ -22,7 +22,6 @@
#include <gtsam/base/lieProxies.h> #include <gtsam/base/lieProxies.h>
#include <CppUnitLite/TestHarness.h> #include <CppUnitLite/TestHarness.h>
#include <boost/foreach.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/assign/std/vector.hpp> // for operator += #include <boost/assign/std/vector.hpp> // for operator +=
#include <cmath> #include <cmath>

View File

@ -33,7 +33,6 @@
#include <CppUnitLite/TestHarness.h> #include <CppUnitLite/TestHarness.h>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/foreach.hpp>
#include <boost/random.hpp> #include <boost/random.hpp>
#include <boost/assign/std/vector.hpp> #include <boost/assign/std/vector.hpp>
#include <cmath> #include <cmath>
@ -56,7 +55,7 @@ TEST(Unit3, point3) {
ps += Point3(1, 0, 0), Point3(0, 1, 0), Point3(0, 0, 1), Point3(1, 1, 0) ps += Point3(1, 0, 0), Point3(0, 1, 0), Point3(0, 0, 1), Point3(1, 1, 0)
/ sqrt(2.0); / sqrt(2.0);
Matrix actualH, expectedH; Matrix actualH, expectedH;
BOOST_FOREACH(Point3 p,ps) { for(Point3 p: ps) {
Unit3 s(p); Unit3 s(p);
expectedH = numericalDerivative11<Point3, Unit3>(point3_, s); expectedH = numericalDerivative11<Point3, Unit3>(point3_, s);
EXPECT(assert_equal(p, s.point3(actualH), 1e-8)); EXPECT(assert_equal(p, s.point3(actualH), 1e-8));

View File

@ -237,7 +237,7 @@ Point3 triangulatePoint3(const std::vector<Pose3>& poses,
// construct projection matrices from poses & calibration // construct projection matrices from poses & calibration
std::vector<Matrix34> projection_matrices; std::vector<Matrix34> projection_matrices;
CameraProjectionMatrix<CALIBRATION> createP(*sharedCal); // partially apply CameraProjectionMatrix<CALIBRATION> createP(*sharedCal); // partially apply
BOOST_FOREACH(const Pose3& pose, poses) for(const Pose3& pose: poses)
projection_matrices.push_back(createP(pose)); projection_matrices.push_back(createP(pose));
// Triangulate linearly // Triangulate linearly
@ -250,7 +250,7 @@ Point3 triangulatePoint3(const std::vector<Pose3>& poses,
#ifdef GTSAM_THROW_CHEIRALITY_EXCEPTION #ifdef GTSAM_THROW_CHEIRALITY_EXCEPTION
// verify that the triangulated point lies in front of all cameras // verify that the triangulated point lies in front of all cameras
BOOST_FOREACH(const Pose3& pose, poses) { for(const Pose3& pose: poses) {
const Point3& p_local = pose.transform_to(point); const Point3& p_local = pose.transform_to(point);
if (p_local.z() <= 0) if (p_local.z() <= 0)
throw(TriangulationCheiralityException()); throw(TriangulationCheiralityException());
@ -286,7 +286,7 @@ Point3 triangulatePoint3(
// construct projection matrices from poses & calibration // construct projection matrices from poses & calibration
std::vector<Matrix34> projection_matrices; std::vector<Matrix34> projection_matrices;
BOOST_FOREACH(const CAMERA& camera, cameras) for(const CAMERA& camera: cameras)
projection_matrices.push_back( projection_matrices.push_back(
CameraProjectionMatrix<typename CAMERA::CalibrationType>(camera.calibration())( CameraProjectionMatrix<typename CAMERA::CalibrationType>(camera.calibration())(
camera.pose())); camera.pose()));
@ -298,7 +298,7 @@ Point3 triangulatePoint3(
#ifdef GTSAM_THROW_CHEIRALITY_EXCEPTION #ifdef GTSAM_THROW_CHEIRALITY_EXCEPTION
// verify that the triangulated point lies in front of all cameras // verify that the triangulated point lies in front of all cameras
BOOST_FOREACH(const CAMERA& camera, cameras) { for(const CAMERA& camera: cameras) {
const Point3& p_local = camera.pose().transform_to(point); const Point3& p_local = camera.pose().transform_to(point);
if (p_local.z() <= 0) if (p_local.z() <= 0)
throw(TriangulationCheiralityException()); throw(TriangulationCheiralityException());
@ -454,7 +454,7 @@ TriangulationResult triangulateSafe(const std::vector<CAMERA>& cameras,
// Check landmark distance and re-projection errors to avoid outliers // Check landmark distance and re-projection errors to avoid outliers
size_t i = 0; size_t i = 0;
double totalReprojError = 0.0; double totalReprojError = 0.0;
BOOST_FOREACH(const CAMERA& camera, cameras) { for(const CAMERA& camera: cameras) {
const Pose3& pose = camera.pose(); const Pose3& pose = camera.pose();
if (params.landmarkDistanceThreshold > 0 if (params.landmarkDistanceThreshold > 0
&& distance(pose.translation(), point) && distance(pose.translation(), point)

View File

@ -21,7 +21,7 @@
#include <gtsam/inference/FactorGraph-inst.h> #include <gtsam/inference/FactorGraph-inst.h>
#include <gtsam/inference/BayesNet.h> #include <gtsam/inference/BayesNet.h>
#include <boost/foreach.hpp> #include <boost/range/adaptor/reversed.hpp>
#include <fstream> #include <fstream>
namespace gtsam { namespace gtsam {
@ -40,11 +40,11 @@ namespace gtsam {
std::ofstream of(s.c_str()); std::ofstream of(s.c_str());
of << "digraph G{\n"; of << "digraph G{\n";
BOOST_REVERSE_FOREACH(const sharedConditional& conditional, *this) { for (auto conditional: boost::adaptors::reverse(*this)) {
typename CONDITIONAL::Frontals frontals = conditional->frontals(); typename CONDITIONAL::Frontals frontals = conditional->frontals();
Key me = frontals.front(); Key me = frontals.front();
typename CONDITIONAL::Parents parents = conditional->parents(); typename CONDITIONAL::Parents parents = conditional->parents();
BOOST_FOREACH(Key p, parents) for(Key p: parents)
of << keyFormatter(p) << "->" << keyFormatter(me) << std::endl; of << keyFormatter(p) << "->" << keyFormatter(me) << std::endl;
} }

View File

@ -26,7 +26,6 @@
#include <gtsam/base/timing.h> #include <gtsam/base/timing.h>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/foreach.hpp>
#include <boost/assign/list_of.hpp> #include <boost/assign/list_of.hpp>
#include <fstream> #include <fstream>
@ -38,7 +37,7 @@ namespace gtsam {
template<class CLIQUE> template<class CLIQUE>
BayesTreeCliqueData BayesTree<CLIQUE>::getCliqueData() const { BayesTreeCliqueData BayesTree<CLIQUE>::getCliqueData() const {
BayesTreeCliqueData data; BayesTreeCliqueData data;
BOOST_FOREACH(const sharedClique& root, roots_) for(const sharedClique& root: roots_)
getCliqueData(data, root); getCliqueData(data, root);
return data; return data;
} }
@ -48,7 +47,7 @@ namespace gtsam {
void BayesTree<CLIQUE>::getCliqueData(BayesTreeCliqueData& data, sharedClique clique) const { void BayesTree<CLIQUE>::getCliqueData(BayesTreeCliqueData& data, sharedClique clique) const {
data.conditionalSizes.push_back(clique->conditional()->nrFrontals()); data.conditionalSizes.push_back(clique->conditional()->nrFrontals());
data.separatorSizes.push_back(clique->conditional()->nrParents()); data.separatorSizes.push_back(clique->conditional()->nrParents());
BOOST_FOREACH(sharedClique c, clique->children) { for(sharedClique c: clique->children) {
getCliqueData(data, c); getCliqueData(data, c);
} }
} }
@ -57,7 +56,7 @@ namespace gtsam {
template<class CLIQUE> template<class CLIQUE>
size_t BayesTree<CLIQUE>::numCachedSeparatorMarginals() const { size_t BayesTree<CLIQUE>::numCachedSeparatorMarginals() const {
size_t count = 0; size_t count = 0;
BOOST_FOREACH(const sharedClique& root, roots_) for(const sharedClique& root: roots_)
count += root->numCachedSeparatorMarginals(); count += root->numCachedSeparatorMarginals();
return count; return count;
} }
@ -68,7 +67,7 @@ namespace gtsam {
if (roots_.empty()) throw std::invalid_argument("the root of Bayes tree has not been initialized!"); if (roots_.empty()) throw std::invalid_argument("the root of Bayes tree has not been initialized!");
std::ofstream of(s.c_str()); std::ofstream of(s.c_str());
of<< "digraph G{\n"; of<< "digraph G{\n";
BOOST_FOREACH(const sharedClique& root, roots_) for(const sharedClique& root: roots_)
saveGraph(of, root, keyFormatter); saveGraph(of, root, keyFormatter);
of<<"}"; of<<"}";
of.close(); of.close();
@ -84,7 +83,7 @@ namespace gtsam {
std::string parent = out.str(); std::string parent = out.str();
parent += "[label=\""; parent += "[label=\"";
BOOST_FOREACH(Key index, clique->conditional_->frontals()) { for(Key index: clique->conditional_->frontals()) {
if(!first) parent += ","; first = false; if(!first) parent += ","; first = false;
parent += indexFormatter(index); parent += indexFormatter(index);
} }
@ -95,7 +94,7 @@ namespace gtsam {
} }
first = true; first = true;
BOOST_FOREACH(Key sep, clique->conditional_->parents()) { for(Key sep: clique->conditional_->parents()) {
if(!first) parent += ","; first = false; if(!first) parent += ","; first = false;
parent += indexFormatter(sep); parent += indexFormatter(sep);
} }
@ -103,7 +102,7 @@ namespace gtsam {
s << parent; s << parent;
parentnum = num; parentnum = num;
BOOST_FOREACH(sharedClique c, clique->children) { for(sharedClique c: clique->children) {
num++; num++;
saveGraph(s, c, indexFormatter, parentnum); saveGraph(s, c, indexFormatter, parentnum);
} }
@ -113,7 +112,7 @@ namespace gtsam {
template<class CLIQUE> template<class CLIQUE>
size_t BayesTree<CLIQUE>::size() const { size_t BayesTree<CLIQUE>::size() const {
size_t size = 0; size_t size = 0;
BOOST_FOREACH(const sharedClique& clique, roots_) for(const sharedClique& clique: roots_)
size += clique->treeSize(); size += clique->treeSize();
return size; return size;
} }
@ -121,7 +120,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
template<class CLIQUE> template<class CLIQUE>
void BayesTree<CLIQUE>::addClique(const sharedClique& clique, const sharedClique& parent_clique) { void BayesTree<CLIQUE>::addClique(const sharedClique& clique, const sharedClique& parent_clique) {
BOOST_FOREACH(Key j, clique->conditional()->frontals()) for(Key j: clique->conditional()->frontals())
nodes_[j] = clique; nodes_[j] = clique;
if (parent_clique != NULL) { if (parent_clique != NULL) {
clique->parent_ = parent_clique; clique->parent_ = parent_clique;
@ -189,7 +188,7 @@ namespace gtsam {
this->clear(); this->clear();
boost::shared_ptr<Clique> rootContainer = boost::make_shared<Clique>(); boost::shared_ptr<Clique> rootContainer = boost::make_shared<Clique>();
treeTraversal::DepthFirstForest(other, rootContainer, BayesTreeCloneForestVisitorPre<Clique>); treeTraversal::DepthFirstForest(other, rootContainer, BayesTreeCloneForestVisitorPre<Clique>);
BOOST_FOREACH(const sharedClique& root, rootContainer->children) { for(const sharedClique& root: rootContainer->children) {
root->parent_ = typename Clique::weak_ptr(); // Reset the parent since it's set to the dummy clique root->parent_ = typename Clique::weak_ptr(); // Reset the parent since it's set to the dummy clique
insertRoot(root); insertRoot(root);
} }
@ -234,13 +233,13 @@ namespace gtsam {
template<class CLIQUE> template<class CLIQUE>
void BayesTree<CLIQUE>::fillNodesIndex(const sharedClique& subtree) { void BayesTree<CLIQUE>::fillNodesIndex(const sharedClique& subtree) {
// Add each frontal variable of this root node // Add each frontal variable of this root node
BOOST_FOREACH(const Key& j, subtree->conditional()->frontals()) { for(const Key& j: subtree->conditional()->frontals()) {
bool inserted = nodes_.insert(std::make_pair(j, subtree)).second; bool inserted = nodes_.insert(std::make_pair(j, subtree)).second;
assert(inserted); (void)inserted; assert(inserted); (void)inserted;
} }
// Fill index for each child // Fill index for each child
typedef typename BayesTree<CLIQUE>::sharedClique sharedClique; typedef typename BayesTree<CLIQUE>::sharedClique sharedClique;
BOOST_FOREACH(const sharedClique& child, subtree->children) { for(const sharedClique& child: subtree->children) {
fillNodesIndex(child); } fillNodesIndex(child); }
} }
@ -345,7 +344,7 @@ namespace gtsam {
boost::shared_ptr<typename EliminationTraitsType::BayesTreeType> p_C1_B; { boost::shared_ptr<typename EliminationTraitsType::BayesTreeType> p_C1_B; {
FastVector<Key> C1_minus_B; { FastVector<Key> C1_minus_B; {
KeySet C1_minus_B_set(C1->conditional()->beginParents(), C1->conditional()->endParents()); KeySet C1_minus_B_set(C1->conditional()->beginParents(), C1->conditional()->endParents());
BOOST_FOREACH(const Key j, *B->conditional()) { for(const Key j: *B->conditional()) {
C1_minus_B_set.erase(j); } C1_minus_B_set.erase(j); }
C1_minus_B.assign(C1_minus_B_set.begin(), C1_minus_B_set.end()); C1_minus_B.assign(C1_minus_B_set.begin(), C1_minus_B_set.end());
} }
@ -357,7 +356,7 @@ namespace gtsam {
boost::shared_ptr<typename EliminationTraitsType::BayesTreeType> p_C2_B; { boost::shared_ptr<typename EliminationTraitsType::BayesTreeType> p_C2_B; {
FastVector<Key> C2_minus_B; { FastVector<Key> C2_minus_B; {
KeySet C2_minus_B_set(C2->conditional()->beginParents(), C2->conditional()->endParents()); KeySet C2_minus_B_set(C2->conditional()->beginParents(), C2->conditional()->endParents());
BOOST_FOREACH(const Key j, *B->conditional()) { for(const Key j: *B->conditional()) {
C2_minus_B_set.erase(j); } C2_minus_B_set.erase(j); }
C2_minus_B.assign(C2_minus_B_set.begin(), C2_minus_B_set.end()); C2_minus_B.assign(C2_minus_B_set.begin(), C2_minus_B_set.end());
} }
@ -403,7 +402,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
template<class CLIQUE> template<class CLIQUE>
void BayesTree<CLIQUE>::deleteCachedShortcuts() { void BayesTree<CLIQUE>::deleteCachedShortcuts() {
BOOST_FOREACH(const sharedClique& root, roots_) { for(const sharedClique& root: roots_) {
root->deleteCachedShortcuts(); root->deleteCachedShortcuts();
} }
} }
@ -424,10 +423,10 @@ namespace gtsam {
} }
// orphan my children // orphan my children
BOOST_FOREACH(sharedClique child, clique->children) for(sharedClique child: clique->children)
child->parent_ = typename Clique::weak_ptr(); child->parent_ = typename Clique::weak_ptr();
BOOST_FOREACH(Key j, clique->conditional()->frontals()) { for(Key j: clique->conditional()->frontals()) {
nodes_.unsafe_erase(j); nodes_.unsafe_erase(j);
} }
} }
@ -462,7 +461,7 @@ namespace gtsam {
void BayesTree<CLIQUE>::removeTop(const FastVector<Key>& keys, BayesNetType& bn, Cliques& orphans) void BayesTree<CLIQUE>::removeTop(const FastVector<Key>& keys, BayesNetType& bn, Cliques& orphans)
{ {
// process each key of the new factor // process each key of the new factor
BOOST_FOREACH(const Key& j, keys) for(const Key& j: keys)
{ {
// get the clique // get the clique
// TODO: Nodes will be searched again in removeClique // TODO: Nodes will be searched again in removeClique
@ -475,7 +474,7 @@ namespace gtsam {
// Delete cachedShortcuts for each orphan subtree // Delete cachedShortcuts for each orphan subtree
//TODO: Consider Improving //TODO: Consider Improving
BOOST_FOREACH(sharedClique& orphan, orphans) for(sharedClique& orphan: orphans)
orphan->deleteCachedShortcuts(); orphan->deleteCachedShortcuts();
} }
@ -499,14 +498,14 @@ namespace gtsam {
for(typename Cliques::iterator clique = cliques.begin(); clique != cliques.end(); ++clique) for(typename Cliques::iterator clique = cliques.begin(); clique != cliques.end(); ++clique)
{ {
// Add children // Add children
BOOST_FOREACH(const sharedClique& child, (*clique)->children) { for(const sharedClique& child: (*clique)->children) {
cliques.push_back(child); } cliques.push_back(child); }
// Delete cached shortcuts // Delete cached shortcuts
(*clique)->deleteCachedShortcutsNonRecursive(); (*clique)->deleteCachedShortcutsNonRecursive();
// Remove this node from the nodes index // Remove this node from the nodes index
BOOST_FOREACH(Key j, (*clique)->conditional()->frontals()) { for(Key j: (*clique)->conditional()->frontals()) {
nodes_.unsafe_erase(j); } nodes_.unsafe_erase(j); }
// Erase the parent and children pointers // Erase the parent and children pointers

View File

@ -20,7 +20,6 @@
#include <gtsam/inference/BayesTree.h> #include <gtsam/inference/BayesTree.h>
#include <boost/foreach.hpp>
#include <iostream> #include <iostream>
namespace gtsam { namespace gtsam {
@ -41,7 +40,7 @@ BayesTreeCliqueStats BayesTreeCliqueData::getStats() const
double sum = 0.0; double sum = 0.0;
size_t max = 0; size_t max = 0;
BOOST_FOREACH(size_t s, conditionalSizes) { for(size_t s: conditionalSizes) {
sum += (double)s; sum += (double)s;
if(s > max) max = s; if(s > max) max = s;
} }
@ -50,7 +49,7 @@ BayesTreeCliqueStats BayesTreeCliqueData::getStats() const
sum = 0.0; sum = 0.0;
max = 1; max = 1;
BOOST_FOREACH(size_t s, separatorSizes) { for(size_t s: separatorSizes) {
sum += (double)s; sum += (double)s;
if(s > max) max = s; if(s > max) max = s;
} }

View File

@ -18,7 +18,6 @@
#include <gtsam/inference/BayesTreeCliqueBase.h> #include <gtsam/inference/BayesTreeCliqueBase.h>
#include <gtsam/base/timing.h> #include <gtsam/base/timing.h>
#include <boost/foreach.hpp>
namespace gtsam { namespace gtsam {
@ -83,7 +82,7 @@ namespace gtsam {
template<class DERIVED, class FACTORGRAPH> template<class DERIVED, class FACTORGRAPH>
size_t BayesTreeCliqueBase<DERIVED, FACTORGRAPH>::treeSize() const { size_t BayesTreeCliqueBase<DERIVED, FACTORGRAPH>::treeSize() const {
size_t size = 1; size_t size = 1;
BOOST_FOREACH(const derived_ptr& child, children) for(const derived_ptr& child: children)
size += child->treeSize(); size += child->treeSize();
return size; return size;
} }
@ -96,7 +95,7 @@ namespace gtsam {
return 0; return 0;
size_t subtree_count = 1; size_t subtree_count = 1;
BOOST_FOREACH(const derived_ptr& child, children) for(const derived_ptr& child: children)
subtree_count += child->numCachedSeparatorMarginals(); subtree_count += child->numCachedSeparatorMarginals();
return subtree_count; return subtree_count;
@ -204,7 +203,7 @@ namespace gtsam {
// root are also generated. So, if this clique's cached shortcut is set, // root are also generated. So, if this clique's cached shortcut is set,
// recursively call over all child cliques. Otherwise, it is unnecessary. // recursively call over all child cliques. Otherwise, it is unnecessary.
if (cachedSeparatorMarginal_) { if (cachedSeparatorMarginal_) {
BOOST_FOREACH(derived_ptr& child, children) { for(derived_ptr& child: children) {
child->deleteCachedShortcuts(); child->deleteCachedShortcuts();
} }

View File

@ -13,7 +13,6 @@
#include <gtsam/base/timing.h> #include <gtsam/base/timing.h>
#include <gtsam/base/treeTraversal-inst.h> #include <gtsam/base/treeTraversal-inst.h>
#include <boost/foreach.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
namespace gtsam { namespace gtsam {
@ -87,7 +86,7 @@ struct EliminationData {
gatheredFactors += myData.childFactors; gatheredFactors += myData.childFactors;
// Check for Bayes tree orphan subtrees, and add them to our children // Check for Bayes tree orphan subtrees, and add them to our children
BOOST_FOREACH(const sharedFactor& f, node->factors) { for(const sharedFactor& f: node->factors) {
if (const BayesTreeOrphanWrapper<BTNode>* asSubtree = if (const BayesTreeOrphanWrapper<BTNode>* asSubtree =
dynamic_cast<const BayesTreeOrphanWrapper<BTNode>*>(f.get())) { dynamic_cast<const BayesTreeOrphanWrapper<BTNode>*>(f.get())) {
myData.bayesTreeNode->children.push_back(asSubtree->clique); myData.bayesTreeNode->children.push_back(asSubtree->clique);
@ -107,7 +106,7 @@ struct EliminationData {
// Fill nodes index - we do this here instead of calling insertRoot at the end to avoid // Fill nodes index - we do this here instead of calling insertRoot at the end to avoid
// putting orphan subtrees in the index - they'll already be in the index of the ISAM2 // putting orphan subtrees in the index - they'll already be in the index of the ISAM2
// object they're added to. // object they're added to.
BOOST_FOREACH(const Key& j, myData.bayesTreeNode->conditional()->frontals()) for(const Key& j: myData.bayesTreeNode->conditional()->frontals())
nodesIndex_.insert(std::make_pair(j, myData.bayesTreeNode)); nodesIndex_.insert(std::make_pair(j, myData.bayesTreeNode));
// Store remaining factor in parent's gathered factors // Store remaining factor in parent's gathered factors
@ -138,7 +137,7 @@ void ClusterTree<BAYESTREE, GRAPH>::Cluster::mergeChildren(
size_t nrNewChildren = 0; size_t nrNewChildren = 0;
// Loop over children // Loop over children
size_t i = 0; size_t i = 0;
BOOST_FOREACH(const sharedNode& child, children) { for(const sharedNode& child: children) {
if (merge[i]) { if (merge[i]) {
nrKeys += child->orderedFrontalKeys.size(); nrKeys += child->orderedFrontalKeys.size();
nrFactors += child->factors.size(); nrFactors += child->factors.size();
@ -155,7 +154,7 @@ void ClusterTree<BAYESTREE, GRAPH>::Cluster::mergeChildren(
typename Node::Children newChildren; typename Node::Children newChildren;
newChildren.reserve(nrNewChildren); newChildren.reserve(nrNewChildren);
i = 0; i = 0;
BOOST_FOREACH(const sharedNode& child, children) { for(const sharedNode& child: children) {
if (merge[i]) { if (merge[i]) {
// Merge keys. For efficiency, we add keys in reverse order at end, calling reverse after.. // Merge keys. For efficiency, we add keys in reverse order at end, calling reverse after..
orderedFrontalKeys.insert(orderedFrontalKeys.end(), orderedFrontalKeys.insert(orderedFrontalKeys.end(),
@ -228,7 +227,7 @@ std::pair<boost::shared_ptr<BAYESTREE>, boost::shared_ptr<GRAPH> > ClusterTree<
remaining->reserve( remaining->reserve(
remainingFactors_.size() + rootsContainer.childFactors.size()); remainingFactors_.size() + rootsContainer.childFactors.size());
remaining->push_back(remainingFactors_.begin(), remainingFactors_.end()); remaining->push_back(remainingFactors_.begin(), remainingFactors_.end());
BOOST_FOREACH(const sharedFactor& factor, rootsContainer.childFactors) { for(const sharedFactor& factor: rootsContainer.childFactors) {
if (factor) if (factor)
remaining->push_back(factor); remaining->push_back(factor);
} }

View File

@ -18,7 +18,6 @@
// \callgraph // \callgraph
#pragma once #pragma once
#include <boost/foreach.hpp>
#include <iostream> #include <iostream>
#include <gtsam/inference/Conditional.h> #include <gtsam/inference/Conditional.h>
@ -29,11 +28,11 @@ namespace gtsam {
template<class FACTOR, class DERIVEDFACTOR> template<class FACTOR, class DERIVEDFACTOR>
void Conditional<FACTOR,DERIVEDFACTOR>::print(const std::string& s, const KeyFormatter& formatter) const { void Conditional<FACTOR,DERIVEDFACTOR>::print(const std::string& s, const KeyFormatter& formatter) const {
std::cout << s << " P("; std::cout << s << " P(";
BOOST_FOREACH(Key key, frontals()) for(Key key: frontals())
std::cout << " " << formatter(key); std::cout << " " << formatter(key);
if (nrParents() > 0) if (nrParents() > 0)
std::cout << " |"; std::cout << " |";
BOOST_FOREACH(Key parent, parents()) for(Key parent: parents())
std::cout << " " << formatter(parent); std::cout << " " << formatter(parent);
std::cout << ")" << std::endl; std::cout << ")" << std::endl;
} }

View File

@ -17,7 +17,6 @@
*/ */
#pragma once #pragma once
#include <boost/foreach.hpp>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <stack> #include <stack>
@ -66,7 +65,7 @@ namespace gtsam {
const std::string& str, const KeyFormatter& keyFormatter) const const std::string& str, const KeyFormatter& keyFormatter) const
{ {
std::cout << str << "(" << keyFormatter(key) << ")\n"; std::cout << str << "(" << keyFormatter(key) << ")\n";
BOOST_FOREACH(const sharedFactor& factor, factors) { for(const sharedFactor& factor: factors) {
if(factor) if(factor)
factor->print(str); factor->print(str);
else else
@ -107,7 +106,7 @@ namespace gtsam {
// for row i \in Struct[A*j] do // for row i \in Struct[A*j] do
node->children.reserve(factors.size()); node->children.reserve(factors.size());
node->factors.reserve(factors.size()); node->factors.reserve(factors.size());
BOOST_FOREACH(const size_t i, factors) { for(const size_t i: factors) {
// If we already hit a variable in this factor, make the subtree containing the previous // If we already hit a variable in this factor, make the subtree containing the previous
// variable in this factor a child of the current node. This means that the variables // variable in this factor a child of the current node. This means that the variables
// eliminated earlier in the factor depend on the later variables in the factor. If we // eliminated earlier in the factor depend on the later variables in the factor. If we
@ -222,15 +221,15 @@ namespace gtsam {
// Add roots in sorted order // Add roots in sorted order
{ {
FastMap<Key,sharedNode> keys; FastMap<Key,sharedNode> keys;
BOOST_FOREACH(const sharedNode& root, this->roots_) { keys.insert(std::make_pair(root->key, root)); } for(const sharedNode& root: this->roots_) { keys.insert(std::make_pair(root->key, root)); }
typedef typename FastMap<Key,sharedNode>::value_type Key_Node; typedef typename FastMap<Key,sharedNode>::value_type Key_Node;
BOOST_FOREACH(const Key_Node& key_node, keys) { stack1.push(key_node.second); } for(const Key_Node& key_node: keys) { stack1.push(key_node.second); }
} }
{ {
FastMap<Key,sharedNode> keys; FastMap<Key,sharedNode> keys;
BOOST_FOREACH(const sharedNode& root, expected.roots_) { keys.insert(std::make_pair(root->key, root)); } for(const sharedNode& root: expected.roots_) { keys.insert(std::make_pair(root->key, root)); }
typedef typename FastMap<Key,sharedNode>::value_type Key_Node; typedef typename FastMap<Key,sharedNode>::value_type Key_Node;
BOOST_FOREACH(const Key_Node& key_node, keys) { stack2.push(key_node.second); } for(const Key_Node& key_node: keys) { stack2.push(key_node.second); }
} }
// Traverse, adding children in sorted order // Traverse, adding children in sorted order
@ -262,15 +261,15 @@ namespace gtsam {
// Add children in sorted order // Add children in sorted order
{ {
FastMap<Key,sharedNode> keys; FastMap<Key,sharedNode> keys;
BOOST_FOREACH(const sharedNode& node, node1->children) { keys.insert(std::make_pair(node->key, node)); } for(const sharedNode& node: node1->children) { keys.insert(std::make_pair(node->key, node)); }
typedef typename FastMap<Key,sharedNode>::value_type Key_Node; typedef typename FastMap<Key,sharedNode>::value_type Key_Node;
BOOST_FOREACH(const Key_Node& key_node, keys) { stack1.push(key_node.second); } for(const Key_Node& key_node: keys) { stack1.push(key_node.second); }
} }
{ {
FastMap<Key,sharedNode> keys; FastMap<Key,sharedNode> keys;
BOOST_FOREACH(const sharedNode& node, node2->children) { keys.insert(std::make_pair(node->key, node)); } for(const sharedNode& node: node2->children) { keys.insert(std::make_pair(node->key, node)); }
typedef typename FastMap<Key,sharedNode>::value_type Key_Node; typedef typename FastMap<Key,sharedNode>::value_type Key_Node;
BOOST_FOREACH(const Key_Node& key_node, keys) { stack2.push(key_node.second); } for(const Key_Node& key_node: keys) { stack2.push(key_node.second); }
} }
} }

View File

@ -19,7 +19,6 @@
// \callgraph // \callgraph
#include <boost/foreach.hpp>
#include <iostream> #include <iostream>
#include <gtsam/inference/Factor.h> #include <gtsam/inference/Factor.h>
@ -35,7 +34,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
void Factor::printKeys(const std::string& s, const KeyFormatter& formatter) const { void Factor::printKeys(const std::string& s, const KeyFormatter& formatter) const {
std::cout << s << " "; std::cout << s << " ";
BOOST_FOREACH(Key key, keys_) std::cout << " " << formatter(key); for(Key key: keys_) std::cout << " " << formatter(key);
std::cout << std::endl; std::cout << std::endl;
} }
@ -44,4 +43,4 @@ namespace gtsam {
return keys_ == other.keys_; return keys_ == other.keys_;
} }
} }

View File

@ -23,7 +23,6 @@
#include <gtsam/inference/FactorGraph.h> #include <gtsam/inference/FactorGraph.h>
#include <boost/foreach.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <stdio.h> #include <stdio.h>
@ -66,7 +65,7 @@ namespace gtsam {
template<class FACTOR> template<class FACTOR>
size_t FactorGraph<FACTOR>::nrFactors() const { size_t FactorGraph<FACTOR>::nrFactors() const {
size_t size_ = 0; size_t size_ = 0;
BOOST_FOREACH(const sharedFactor& factor, factors_) for(const sharedFactor& factor: factors_)
if (factor) size_++; if (factor) size_++;
return size_; return size_;
} }
@ -75,7 +74,7 @@ namespace gtsam {
template<class FACTOR> template<class FACTOR>
KeySet FactorGraph<FACTOR>::keys() const { KeySet FactorGraph<FACTOR>::keys() const {
KeySet keys; KeySet keys;
BOOST_FOREACH(const sharedFactor& factor, this->factors_) { for(const sharedFactor& factor: this->factors_) {
if(factor) if(factor)
keys.insert(factor->begin(), factor->end()); keys.insert(factor->begin(), factor->end());
} }
@ -87,7 +86,7 @@ namespace gtsam {
KeyVector FactorGraph<FACTOR>::keyVector() const { KeyVector FactorGraph<FACTOR>::keyVector() const {
KeyVector keys; KeyVector keys;
keys.reserve(2 * size()); // guess at size keys.reserve(2 * size()); // guess at size
BOOST_FOREACH (const sharedFactor& factor, factors_) for (const sharedFactor& factor: factors_)
if (factor) if (factor)
keys.insert(keys.end(), factor->begin(), factor->end()); keys.insert(keys.end(), factor->begin(), factor->end());
std::sort(keys.begin(), keys.end()); std::sort(keys.begin(), keys.end());

View File

@ -39,7 +39,7 @@ namespace gtsam {
factors += newFactors; factors += newFactors;
// Add the orphaned subtrees // Add the orphaned subtrees
BOOST_FOREACH(const sharedClique& orphan, orphans) for(const sharedClique& orphan: orphans)
factors += boost::make_shared<BayesTreeOrphanWrapper<Clique> >(orphan); factors += boost::make_shared<BayesTreeOrphanWrapper<Clique> >(orphan);
// eliminate into a Bayes net // eliminate into a Bayes net

View File

@ -105,7 +105,7 @@ struct ConstructorTraversalData {
// decide which children to merge, as index into children // decide which children to merge, as index into children
std::vector<bool> merge(nrChildren, false); std::vector<bool> merge(nrChildren, false);
size_t myNrFrontals = 1, i = 0; size_t myNrFrontals = 1, i = 0;
BOOST_FOREACH(const sharedNode& child, node->children) { for(const sharedNode& child: node->children) {
// Check if we should merge the i^th child // Check if we should merge the i^th child
if (myNrParents + myNrFrontals == childConditionals[i]->nrParents()) { if (myNrParents + myNrFrontals == childConditionals[i]->nrParents()) {
// Increment number of frontal variables // Increment number of frontal variables

View File

@ -20,7 +20,6 @@
#include <gtsam/inference/Key.h> #include <gtsam/inference/Key.h>
#include <gtsam/inference/LabeledSymbol.h> #include <gtsam/inference/LabeledSymbol.h>
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <iostream> #include <iostream>
@ -63,7 +62,7 @@ static void Print(const CONTAINER& keys, const string& s,
if (keys.empty()) if (keys.empty())
cout << "(none)" << endl; cout << "(none)" << endl;
else { else {
BOOST_FOREACH(const Key& key, keys) for(const Key& key: keys)
cout << keyFormatter(key) << " "; cout << keyFormatter(key) << " ";
cout << endl; cout << endl;
} }

View File

@ -17,7 +17,6 @@
#pragma once #pragma once
#include <boost/foreach.hpp>
#include <map> #include <map>
#include <vector> #include <vector>
@ -42,7 +41,7 @@ void MetisIndex::augment(const FactorGraph<FACTOR>& factors) {
// key to integer mapping. This is referenced during the adjaceny step // key to integer mapping. This is referenced during the adjaceny step
for (size_t i = 0; i < factors.size(); i++) { for (size_t i = 0; i < factors.size(); i++) {
if (factors[i]) { if (factors[i]) {
BOOST_FOREACH(const Key& key, *factors[i]) { for(const Key& key: *factors[i]) {
keySet.insert(keySet.end(), key); // Keep a track of all unique keys keySet.insert(keySet.end(), key); // Keep a track of all unique keys
if (intKeyBMap_.left.find(key) == intKeyBMap_.left.end()) { if (intKeyBMap_.left.find(key) == intKeyBMap_.left.end()) {
intKeyBMap_.insert(bm_type::value_type(key, keyCounter)); intKeyBMap_.insert(bm_type::value_type(key, keyCounter));
@ -55,8 +54,8 @@ void MetisIndex::augment(const FactorGraph<FACTOR>& factors) {
// Create an adjacency mapping that stores the set of all adjacent keys for every key // Create an adjacency mapping that stores the set of all adjacent keys for every key
for (size_t i = 0; i < factors.size(); i++) { for (size_t i = 0; i < factors.size(); i++) {
if (factors[i]) { if (factors[i]) {
BOOST_FOREACH(const Key& k1, *factors[i]) for(const Key& k1: *factors[i])
BOOST_FOREACH(const Key& k2, *factors[i]) for(const Key& k2: *factors[i])
if (k1 != k2) { if (k1 != k2) {
// Store both in Key and int32_t format // Store both in Key and int32_t format
int i = intKeyBMap_.left.at(k1); int i = intKeyBMap_.left.at(k1);

View File

@ -19,7 +19,6 @@
#include <gtsam/inference/VariableIndex.h> #include <gtsam/inference/VariableIndex.h>
#include <gtsam/base/timing.h> #include <gtsam/base/timing.h>
#include <boost/foreach.hpp>
namespace gtsam { namespace gtsam {
@ -34,7 +33,7 @@ void VariableIndex::augment(const FG& factors,
if (factors[i]) { if (factors[i]) {
const size_t globalI = const size_t globalI =
newFactorIndices ? (*newFactorIndices)[i] : nFactors_; newFactorIndices ? (*newFactorIndices)[i] : nFactors_;
BOOST_FOREACH(const Key key, *factors[i]) { for(const Key key: *factors[i]) {
index_[key].push_back(globalI); index_[key].push_back(globalI);
++nEntries_; ++nEntries_;
} }
@ -67,7 +66,7 @@ void VariableIndex::remove(ITERATOR firstFactor, ITERATOR lastFactor,
throw std::invalid_argument( throw std::invalid_argument(
"Internal error, requested inconsistent number of factor indices and factors in VariableIndex::remove"); "Internal error, requested inconsistent number of factor indices and factors in VariableIndex::remove");
if (factors[i]) { if (factors[i]) {
BOOST_FOREACH(Key j, *factors[i]) { for(Key j: *factors[i]) {
Factors& factorEntries = internalAt(j); Factors& factorEntries = internalAt(j);
Factors::iterator entry = std::find(factorEntries.begin(), Factors::iterator entry = std::find(factorEntries.begin(),
factorEntries.end(), *factorIndex); factorEntries.end(), *factorIndex);

View File

@ -33,9 +33,9 @@ bool VariableIndex::equals(const VariableIndex& other, double tol) const {
void VariableIndex::print(const string& str, const KeyFormatter& keyFormatter) const { void VariableIndex::print(const string& str, const KeyFormatter& keyFormatter) const {
cout << str; cout << str;
cout << "nEntries = " << nEntries() << ", nFactors = " << nFactors() << "\n"; cout << "nEntries = " << nEntries() << ", nFactors = " << nFactors() << "\n";
BOOST_FOREACH(KeyMap::value_type key_factors, index_) { for(KeyMap::value_type key_factors: index_) {
cout << "var " << keyFormatter(key_factors.first) << ":"; cout << "var " << keyFormatter(key_factors.first) << ":";
BOOST_FOREACH(const size_t factor, key_factors.second) for(const size_t factor: key_factors.second)
cout << " " << factor; cout << " " << factor;
cout << "\n"; cout << "\n";
} }
@ -46,9 +46,9 @@ void VariableIndex::print(const string& str, const KeyFormatter& keyFormatter) c
void VariableIndex::outputMetisFormat(ostream& os) const { void VariableIndex::outputMetisFormat(ostream& os) const {
os << size() << " " << nFactors() << "\n"; os << size() << " " << nFactors() << "\n";
// run over variables, which will be hyper-edges. // run over variables, which will be hyper-edges.
BOOST_FOREACH(KeyMap::value_type key_factors, index_) { for(KeyMap::value_type key_factors: index_) {
// every variable is a hyper-edge covering its factors // every variable is a hyper-edge covering its factors
BOOST_FOREACH(const size_t factor, key_factors.second) for(const size_t factor: key_factors.second)
os << (factor+1) << " "; // base 1 os << (factor+1) << " "; // base 1
os << "\n"; os << "\n";
} }

View File

@ -18,7 +18,6 @@
#include <gtsam/inference/VariableSlots.h> #include <gtsam/inference/VariableSlots.h>
#include <iostream> #include <iostream>
#include <boost/foreach.hpp>
using namespace std; using namespace std;
@ -33,12 +32,12 @@ void VariableSlots::print(const std::string& str) const {
else { else {
cout << str << "\n"; cout << str << "\n";
cout << "Var:\t"; cout << "Var:\t";
BOOST_FOREACH(const value_type& slot, *this) { cout << slot.first << "\t"; } for(const value_type& slot: *this) { cout << slot.first << "\t"; }
cout << "\n"; cout << "\n";
for(size_t i=0; i<this->begin()->second.size(); ++i) { for(size_t i=0; i<this->begin()->second.size(); ++i) {
cout << " \t"; cout << " \t";
BOOST_FOREACH(const value_type& slot, *this) { for(const value_type& slot: *this) {
if(slot.second[i] == Empty) if(slot.second[i] == Empty)
cout << "x" << "\t"; cout << "x" << "\t";
else else

View File

@ -24,7 +24,6 @@
#include <gtsam/base/timing.h> #include <gtsam/base/timing.h>
#include <gtsam/base/Testable.h> #include <gtsam/base/Testable.h>
#include <boost/foreach.hpp>
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include <iostream> #include <iostream>
@ -99,10 +98,10 @@ VariableSlots::VariableSlots(const FG& factorGraph)
// removed factors. The slot number is the max integer value if the // removed factors. The slot number is the max integer value if the
// factor does not involve that variable. // factor does not involve that variable.
size_t jointFactorPos = 0; size_t jointFactorPos = 0;
BOOST_FOREACH(const typename FG::sharedFactor& factor, factorGraph) { for(const typename FG::sharedFactor& factor: factorGraph) {
assert(factor); assert(factor);
size_t factorVarSlot = 0; size_t factorVarSlot = 0;
BOOST_FOREACH(const Key involvedVariable, *factor) { for(const Key involvedVariable: *factor) {
// Set the slot in this factor for this variable. If the // Set the slot in this factor for this variable. If the
// variable was not already discovered, create an array for it // variable was not already discovered, create an array for it
// that we'll fill with the slot indices for each factor that // that we'll fill with the slot indices for each factor that

View File

@ -18,7 +18,6 @@
#pragma once #pragma once
#include <stdexcept> #include <stdexcept>
#include <boost/foreach.hpp>
#ifdef __GNUC__ #ifdef __GNUC__
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wunused-variable"
@ -32,8 +31,6 @@
#include <gtsam/inference/graph.h> #include <gtsam/inference/graph.h>
#define FOREACH_PAIR( KEY, VAL, COL) BOOST_FOREACH (boost::tie(KEY,VAL),COL)
namespace gtsam { namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
@ -123,9 +120,10 @@ predecessorMap2Graph(const PredecessorMap<KEY>& p_map) {
G g; G g;
std::map<KEY, V> key2vertex; std::map<KEY, V> key2vertex;
V v1, v2, root; V v1, v2, root;
KEY child, parent;
bool foundRoot = false; bool foundRoot = false;
FOREACH_PAIR(child, parent, p_map) { for(auto child_parent: p_map) {
KEY child, parent;
std::tie(child,parent) = child_parent;
if (key2vertex.find(child) == key2vertex.end()) { if (key2vertex.find(child) == key2vertex.end()) {
v1 = add_vertex(child, g); v1 = add_vertex(child, g);
key2vertex.insert(std::make_pair(child, v1)); key2vertex.insert(std::make_pair(child, v1));
@ -193,7 +191,7 @@ boost::shared_ptr<Values> composePoses(const G& graph, const PredecessorMap<KEY>
// attach the relative poses to the edges // attach the relative poses to the edges
PoseEdge edge12, edge21; PoseEdge edge12, edge21;
bool found1, found2; bool found1, found2;
BOOST_FOREACH(typename G::sharedFactor nl_factor, graph) { for(typename G::sharedFactor nl_factor: graph) {
if (nl_factor->keys().size() > 2) if (nl_factor->keys().size() > 2)
throw std::invalid_argument("composePoses: only support factors with at most two keys"); throw std::invalid_argument("composePoses: only support factors with at most two keys");
@ -243,7 +241,7 @@ PredecessorMap<KEY> findMinimumSpanningTree(const G& fg) {
// convert edge to string pairs // convert edge to string pairs
PredecessorMap<KEY> tree; PredecessorMap<KEY> tree;
typename SDGraph<KEY>::vertex_iterator itVertex = boost::vertices(g).first; typename SDGraph<KEY>::vertex_iterator itVertex = boost::vertices(g).first;
BOOST_FOREACH(const typename SDGraph<KEY>::Vertex& vi, p_map){ for(const typename SDGraph<KEY>::Vertex& vi: p_map){
KEY key = boost::get(boost::vertex_name, g, *itVertex); KEY key = boost::get(boost::vertex_name, g, *itVertex);
KEY parent = boost::get(boost::vertex_name, g, vi); KEY parent = boost::get(boost::vertex_name, g, vi);
tree.insert(key, parent); tree.insert(key, parent);
@ -258,7 +256,7 @@ void split(const G& g, const PredecessorMap<KEY>& tree, G& Ab1, G& Ab2) {
typedef typename G::sharedFactor F ; typedef typename G::sharedFactor F ;
BOOST_FOREACH(const F& factor, g) for(const F& factor: g)
{ {
if (factor->keys().size() > 2) if (factor->keys().size() > 2)
throw(std::invalid_argument("split: only support factors with at most two keys")); throw(std::invalid_argument("split: only support factors with at most two keys"));

View File

@ -17,7 +17,6 @@
* @author Christian Potthast * @author Christian Potthast
*/ */
#include <boost/foreach.hpp>
#include <boost/range/adaptor/map.hpp> #include <boost/range/adaptor/map.hpp>
#include <gtsam/linear/Errors.h> #include <gtsam/linear/Errors.h>
#include <gtsam/linear/VectorValues.h> #include <gtsam/linear/VectorValues.h>
@ -31,7 +30,7 @@ Errors::Errors(){}
/* ************************************************************************* */ /* ************************************************************************* */
Errors::Errors(const VectorValues& V) { Errors::Errors(const VectorValues& V) {
BOOST_FOREACH(const Vector& e, V | boost::adaptors::map_values) { for(const Vector& e: V | boost::adaptors::map_values) {
push_back(e); push_back(e);
} }
} }
@ -39,7 +38,7 @@ Errors::Errors(const VectorValues& V) {
/* ************************************************************************* */ /* ************************************************************************* */
void Errors::print(const std::string& s) const { void Errors::print(const std::string& s) const {
cout << s << endl; cout << s << endl;
BOOST_FOREACH(const Vector& v, *this) for(const Vector& v: *this)
gtsam::print(v); gtsam::print(v);
} }
@ -66,7 +65,7 @@ Errors Errors::operator+(const Errors& b) const {
#endif #endif
Errors result; Errors result;
Errors::const_iterator it = b.begin(); Errors::const_iterator it = b.begin();
BOOST_FOREACH(const Vector& ai, *this) for(const Vector& ai: *this)
result.push_back(ai + *(it++)); result.push_back(ai + *(it++));
return result; return result;
} }
@ -81,7 +80,7 @@ Errors Errors::operator-(const Errors& b) const {
#endif #endif
Errors result; Errors result;
Errors::const_iterator it = b.begin(); Errors::const_iterator it = b.begin();
BOOST_FOREACH(const Vector& ai, *this) for(const Vector& ai: *this)
result.push_back(ai - *(it++)); result.push_back(ai - *(it++));
return result; return result;
} }
@ -89,7 +88,7 @@ Errors Errors::operator-(const Errors& b) const {
/* ************************************************************************* */ /* ************************************************************************* */
Errors Errors::operator-() const { Errors Errors::operator-() const {
Errors result; Errors result;
BOOST_FOREACH(const Vector& ai, *this) for(const Vector& ai: *this)
result.push_back(-ai); result.push_back(-ai);
return result; return result;
} }
@ -105,7 +104,7 @@ double dot(const Errors& a, const Errors& b) {
#endif #endif
double result = 0.0; double result = 0.0;
Errors::const_iterator it = b.begin(); Errors::const_iterator it = b.begin();
BOOST_FOREACH(const Vector& ai, a) for(const Vector& ai: a)
result += gtsam::dot(ai, *(it++)); result += gtsam::dot(ai, *(it++));
return result; return result;
} }
@ -114,7 +113,7 @@ double dot(const Errors& a, const Errors& b) {
template<> template<>
void axpy<Errors,Errors>(double alpha, const Errors& x, Errors& y) { void axpy<Errors,Errors>(double alpha, const Errors& x, Errors& y) {
Errors::const_iterator it = x.begin(); Errors::const_iterator it = x.begin();
BOOST_FOREACH(Vector& yi, y) for(Vector& yi: y)
axpy(alpha,*(it++),yi); axpy(alpha,*(it++),yi);
} }

View File

@ -20,14 +20,11 @@
#include <gtsam/inference/FactorGraph-inst.h> #include <gtsam/inference/FactorGraph-inst.h>
#include <gtsam/base/timing.h> #include <gtsam/base/timing.h>
#include <boost/foreach.hpp> #include <boost/range/adaptor/reversed.hpp>
using namespace std; using namespace std;
using namespace gtsam; using namespace gtsam;
#define FOREACH_PAIR( KEY, VAL, COL) BOOST_FOREACH (boost::tie(KEY,VAL),COL)
#define REVERSE_FOREACH_PAIR( KEY, VAL, COL) BOOST_REVERSE_FOREACH (boost::tie(KEY,VAL),COL)
namespace gtsam { namespace gtsam {
// Instantiate base class // Instantiate base class
@ -52,7 +49,7 @@ namespace gtsam {
VectorValues soln(solutionForMissing); // possibly empty VectorValues soln(solutionForMissing); // possibly empty
// (R*x)./sigmas = y by solving x=inv(R)*(y.*sigmas) // (R*x)./sigmas = y by solving x=inv(R)*(y.*sigmas)
/** solve each node in turn in topological sort order (parents first)*/ /** solve each node in turn in topological sort order (parents first)*/
BOOST_REVERSE_FOREACH(const sharedConditional& cg, *this) { for (auto cg: boost::adaptors::reverse(*this)) {
// i^th part of R*x=y, x=inv(R)*y // i^th part of R*x=y, x=inv(R)*y
// (Rii*xi + R_i*x(i+1:))./si = yi <-> xi = inv(Rii)*(yi.*si - R_i*x(i+1:)) // (Rii*xi + R_i*x(i+1:))./si = yi <-> xi = inv(Rii)*(yi.*si - R_i*x(i+1:))
soln.insert(cg->solve(soln)); soln.insert(cg->solve(soln));
@ -88,7 +85,7 @@ namespace gtsam {
VectorValues result; VectorValues result;
// TODO this looks pretty sketchy. result is passed as the parents argument // TODO this looks pretty sketchy. result is passed as the parents argument
// as it's filled up by solving the gaussian conditionals. // as it's filled up by solving the gaussian conditionals.
BOOST_REVERSE_FOREACH(const sharedConditional& cg, *this) { for (auto cg: boost::adaptors::reverse(*this)) {
result.insert(cg->solveOtherRHS(result, rhs)); result.insert(cg->solveOtherRHS(result, rhs));
} }
return result; return result;
@ -107,7 +104,7 @@ namespace gtsam {
// we loop from first-eliminated to last-eliminated // we loop from first-eliminated to last-eliminated
// i^th part of L*gy=gx is done block-column by block-column of L // i^th part of L*gy=gx is done block-column by block-column of L
BOOST_FOREACH(const sharedConditional& cg, *this) for(const sharedConditional& cg: *this)
cg->solveTransposeInPlace(gy); cg->solveTransposeInPlace(gy);
return gy; return gy;
@ -146,15 +143,15 @@ namespace gtsam {
KeySet keys = factorGraph.keys(); KeySet keys = factorGraph.keys();
// add frontal keys in order // add frontal keys in order
Ordering ordering; Ordering ordering;
BOOST_FOREACH (const sharedConditional& cg, *this) for (const sharedConditional& cg: *this)
if (cg) { if (cg) {
BOOST_FOREACH (Key key, cg->frontals()) { for (Key key: cg->frontals()) {
ordering.push_back(key); ordering.push_back(key);
keys.erase(key); keys.erase(key);
} }
} }
// add remaining keys in case Bayes net is incomplete // add remaining keys in case Bayes net is incomplete
BOOST_FOREACH (Key key, keys) for (Key key: keys)
ordering.push_back(key); ordering.push_back(key);
// return matrix and RHS // return matrix and RHS
return factorGraph.jacobian(ordering); return factorGraph.jacobian(ordering);
@ -182,7 +179,7 @@ namespace gtsam {
double GaussianBayesNet::logDeterminant() const double GaussianBayesNet::logDeterminant() const
{ {
double logDet = 0.0; double logDet = 0.0;
BOOST_FOREACH(const sharedConditional& cg, *this) { for(const sharedConditional& cg: *this) {
if(cg->get_model()) { if(cg->get_model()) {
Vector diag = cg->get_R().diagonal(); Vector diag = cg->get_R().diagonal();
cg->get_model()->whitenInPlace(diag); cg->get_model()->whitenInPlace(diag);

View File

@ -19,8 +19,6 @@
#pragma once #pragma once
#include <boost/foreach.hpp>
#include <gtsam/linear/GaussianBayesTree.h> // Only to help Eclipse #include <gtsam/linear/GaussianBayesTree.h> // Only to help Eclipse
#include <stdarg.h> #include <stdarg.h>
@ -35,7 +33,7 @@ void optimizeInPlace(const typename BAYESTREE::sharedClique& clique, VectorValue
clique->conditional()->solveInPlace(result); clique->conditional()->solveInPlace(result);
// starting from the root, call optimize on each conditional // starting from the root, call optimize on each conditional
BOOST_FOREACH(const typename BAYESTREE::sharedClique& child, clique->children_) for(const typename BAYESTREE::sharedClique& child: clique->children_)
optimizeInPlace<BAYESTREE>(child, result); optimizeInPlace<BAYESTREE>(child, result);
} }
@ -48,7 +46,7 @@ double logDeterminant(const typename BAYESTREE::sharedClique& clique) {
result += clique->conditional()->get_R().diagonal().unaryExpr(std::ptr_fun<double,double>(log)).sum(); result += clique->conditional()->get_R().diagonal().unaryExpr(std::ptr_fun<double,double>(log)).sum();
// sum of children // sum of children
BOOST_FOREACH(const typename BAYESTREE::sharedClique& child, clique->children_) for(const typename BAYESTREE::sharedClique& child: clique->children_)
result += logDeterminant<BAYESTREE>(child); result += logDeterminant<BAYESTREE>(child);
return result; return result;

View File

@ -30,8 +30,6 @@
#include <gtsam/base/timing.h> #include <gtsam/base/timing.h>
#include <gtsam/base/cholesky.h> #include <gtsam/base/cholesky.h>
#include <boost/foreach.hpp>
using namespace std; using namespace std;
using namespace gtsam; using namespace gtsam;
@ -50,7 +48,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
GaussianFactorGraph::Keys GaussianFactorGraph::keys() const { GaussianFactorGraph::Keys GaussianFactorGraph::keys() const {
KeySet keys; KeySet keys;
BOOST_FOREACH(const sharedFactor& factor, *this) for(const sharedFactor& factor: *this)
if (factor) if (factor)
keys.insert(factor->begin(), factor->end()); keys.insert(factor->begin(), factor->end());
return keys; return keys;
@ -59,7 +57,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
std::map<Key, size_t> GaussianFactorGraph::getKeyDimMap() const { std::map<Key, size_t> GaussianFactorGraph::getKeyDimMap() const {
map<Key, size_t> spec; map<Key, size_t> spec;
BOOST_FOREACH ( const GaussianFactor::shared_ptr &gf, *this ) { for ( const GaussianFactor::shared_ptr &gf: *this ) {
for ( GaussianFactor::const_iterator it = gf->begin() ; it != gf->end() ; it++ ) { for ( GaussianFactor::const_iterator it = gf->begin() ; it != gf->end() ; it++ ) {
map<Key,size_t>::iterator it2 = spec.find(*it); map<Key,size_t>::iterator it2 = spec.find(*it);
if ( it2 == spec.end() ) { if ( it2 == spec.end() ) {
@ -80,7 +78,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
GaussianFactorGraph GaussianFactorGraph::clone() const { GaussianFactorGraph GaussianFactorGraph::clone() const {
GaussianFactorGraph result; GaussianFactorGraph result;
BOOST_FOREACH(const sharedFactor& f, *this) { for(const sharedFactor& f: *this) {
if (f) if (f)
result.push_back(f->clone()); result.push_back(f->clone());
else else
@ -92,7 +90,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
GaussianFactorGraph GaussianFactorGraph::negate() const { GaussianFactorGraph GaussianFactorGraph::negate() const {
GaussianFactorGraph result; GaussianFactorGraph result;
BOOST_FOREACH(const sharedFactor& f, *this) { for(const sharedFactor& f: *this) {
if (f) if (f)
result.push_back(f->negate()); result.push_back(f->negate());
else else
@ -106,7 +104,7 @@ namespace gtsam {
// First find dimensions of each variable // First find dimensions of each variable
typedef std::map<Key, size_t> KeySizeMap; typedef std::map<Key, size_t> KeySizeMap;
KeySizeMap dims; KeySizeMap dims;
BOOST_FOREACH(const sharedFactor& factor, *this) { for(const sharedFactor& factor: *this) {
if (!static_cast<bool>(factor)) continue; if (!static_cast<bool>(factor)) continue;
for (GaussianFactor::const_iterator key = factor->begin(); for (GaussianFactor::const_iterator key = factor->begin();
@ -118,7 +116,7 @@ namespace gtsam {
// Compute first scalar column of each variable // Compute first scalar column of each variable
size_t currentColIndex = 0; size_t currentColIndex = 0;
KeySizeMap columnIndices = dims; KeySizeMap columnIndices = dims;
BOOST_FOREACH(const KeySizeMap::value_type& col, dims) { for(const KeySizeMap::value_type& col: dims) {
columnIndices[col.first] = currentColIndex; columnIndices[col.first] = currentColIndex;
currentColIndex += dims[col.first]; currentColIndex += dims[col.first];
} }
@ -127,7 +125,7 @@ namespace gtsam {
typedef boost::tuple<size_t, size_t, double> triplet; typedef boost::tuple<size_t, size_t, double> triplet;
vector<triplet> entries; vector<triplet> entries;
size_t row = 0; size_t row = 0;
BOOST_FOREACH(const sharedFactor& factor, *this) { for(const sharedFactor& factor: *this) {
if (!static_cast<bool>(factor)) continue; if (!static_cast<bool>(factor)) continue;
// Convert to JacobianFactor if necessary // Convert to JacobianFactor if necessary
@ -229,7 +227,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
VectorValues GaussianFactorGraph::hessianDiagonal() const { VectorValues GaussianFactorGraph::hessianDiagonal() const {
VectorValues d; VectorValues d;
BOOST_FOREACH(const sharedFactor& factor, *this) { for(const sharedFactor& factor: *this) {
if(factor){ if(factor){
VectorValues di = factor->hessianDiagonal(); VectorValues di = factor->hessianDiagonal();
d.addInPlace_(di); d.addInPlace_(di);
@ -241,7 +239,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
map<Key,Matrix> GaussianFactorGraph::hessianBlockDiagonal() const { map<Key,Matrix> GaussianFactorGraph::hessianBlockDiagonal() const {
map<Key,Matrix> blocks; map<Key,Matrix> blocks;
BOOST_FOREACH(const sharedFactor& factor, *this) { for(const sharedFactor& factor: *this) {
if (!factor) continue; if (!factor) continue;
map<Key,Matrix> BD = factor->hessianBlockDiagonal(); map<Key,Matrix> BD = factor->hessianBlockDiagonal();
map<Key,Matrix>::const_iterator it = BD.begin(); map<Key,Matrix>::const_iterator it = BD.begin();
@ -279,7 +277,7 @@ namespace gtsam {
VectorValues GaussianFactorGraph::gradient(const VectorValues& x0) const VectorValues GaussianFactorGraph::gradient(const VectorValues& x0) const
{ {
VectorValues g = VectorValues::Zero(x0); VectorValues g = VectorValues::Zero(x0);
BOOST_FOREACH(const sharedFactor& Ai_G, *this) { for(const sharedFactor& Ai_G: *this) {
JacobianFactor::shared_ptr Ai = convertToJacobianFactorPtr(Ai_G); JacobianFactor::shared_ptr Ai = convertToJacobianFactorPtr(Ai_G);
Vector e = Ai->error_vector(x0); Vector e = Ai->error_vector(x0);
Ai->transposeMultiplyAdd(1.0, e, g); Ai->transposeMultiplyAdd(1.0, e, g);
@ -291,7 +289,7 @@ namespace gtsam {
VectorValues GaussianFactorGraph::gradientAtZero() const { VectorValues GaussianFactorGraph::gradientAtZero() const {
// Zero-out the gradient // Zero-out the gradient
VectorValues g; VectorValues g;
BOOST_FOREACH(const sharedFactor& factor, *this) { for(const sharedFactor& factor: *this) {
if (!factor) continue; if (!factor) continue;
VectorValues gi = factor->gradientAtZero(); VectorValues gi = factor->gradientAtZero();
g.addInPlace_(gi); g.addInPlace_(gi);
@ -331,7 +329,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
Errors GaussianFactorGraph::operator*(const VectorValues& x) const { Errors GaussianFactorGraph::operator*(const VectorValues& x) const {
Errors e; Errors e;
BOOST_FOREACH(const GaussianFactor::shared_ptr& Ai_G, *this) { for(const GaussianFactor::shared_ptr& Ai_G: *this) {
JacobianFactor::shared_ptr Ai = convertToJacobianFactorPtr(Ai_G); JacobianFactor::shared_ptr Ai = convertToJacobianFactorPtr(Ai_G);
e.push_back((*Ai) * x); e.push_back((*Ai) * x);
} }
@ -341,7 +339,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
void GaussianFactorGraph::multiplyHessianAdd(double alpha, void GaussianFactorGraph::multiplyHessianAdd(double alpha,
const VectorValues& x, VectorValues& y) const { const VectorValues& x, VectorValues& y) const {
BOOST_FOREACH(const GaussianFactor::shared_ptr& f, *this) for(const GaussianFactor::shared_ptr& f: *this)
f->multiplyHessianAdd(alpha, x, y); f->multiplyHessianAdd(alpha, x, y);
} }
@ -353,7 +351,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
void GaussianFactorGraph::multiplyInPlace(const VectorValues& x, const Errors::iterator& e) const { void GaussianFactorGraph::multiplyInPlace(const VectorValues& x, const Errors::iterator& e) const {
Errors::iterator ei = e; Errors::iterator ei = e;
BOOST_FOREACH(const GaussianFactor::shared_ptr& Ai_G, *this) { for(const GaussianFactor::shared_ptr& Ai_G: *this) {
JacobianFactor::shared_ptr Ai = convertToJacobianFactorPtr(Ai_G); JacobianFactor::shared_ptr Ai = convertToJacobianFactorPtr(Ai_G);
*ei = (*Ai)*x; *ei = (*Ai)*x;
ei++; ei++;
@ -363,7 +361,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
bool hasConstraints(const GaussianFactorGraph& factors) { bool hasConstraints(const GaussianFactorGraph& factors) {
typedef JacobianFactor J; typedef JacobianFactor J;
BOOST_FOREACH(const GaussianFactor::shared_ptr& factor, factors) { for(const GaussianFactor::shared_ptr& factor: factors) {
J::shared_ptr jacobian(boost::dynamic_pointer_cast<J>(factor)); J::shared_ptr jacobian(boost::dynamic_pointer_cast<J>(factor));
if (jacobian && jacobian->get_model() && jacobian->get_model()->isConstrained()) { if (jacobian && jacobian->get_model() && jacobian->get_model()->isConstrained()) {
return true; return true;
@ -378,7 +376,7 @@ namespace gtsam {
VectorValues& x) const { VectorValues& x) const {
// For each factor add the gradient contribution // For each factor add the gradient contribution
Errors::const_iterator ei = e.begin(); Errors::const_iterator ei = e.begin();
BOOST_FOREACH(const sharedFactor& Ai_G, *this) { for(const sharedFactor& Ai_G: *this) {
JacobianFactor::shared_ptr Ai = convertToJacobianFactorPtr(Ai_G); JacobianFactor::shared_ptr Ai = convertToJacobianFactorPtr(Ai_G);
Ai->transposeMultiplyAdd(alpha, *(ei++), x); Ai->transposeMultiplyAdd(alpha, *(ei++), x);
} }
@ -387,7 +385,7 @@ namespace gtsam {
///* ************************************************************************* */ ///* ************************************************************************* */
//void residual(const GaussianFactorGraph& fg, const VectorValues &x, VectorValues &r) { //void residual(const GaussianFactorGraph& fg, const VectorValues &x, VectorValues &r) {
// Key i = 0 ; // Key i = 0 ;
// BOOST_FOREACH(const GaussianFactor::shared_ptr& Ai_G, fg) { // for(const GaussianFactor::shared_ptr& Ai_G: fg) {
// JacobianFactor::shared_ptr Ai = convertToJacobianFactorPtr(Ai_G); // JacobianFactor::shared_ptr Ai = convertToJacobianFactorPtr(Ai_G);
// r[i] = Ai->getb(); // r[i] = Ai->getb();
// i++; // i++;
@ -401,7 +399,7 @@ namespace gtsam {
//void multiply(const GaussianFactorGraph& fg, const VectorValues &x, VectorValues &r) { //void multiply(const GaussianFactorGraph& fg, const VectorValues &x, VectorValues &r) {
// r.setZero(); // r.setZero();
// Key i = 0; // Key i = 0;
// BOOST_FOREACH(const GaussianFactor::shared_ptr& Ai_G, fg) { // for(const GaussianFactor::shared_ptr& Ai_G: fg) {
// JacobianFactor::shared_ptr Ai = convertToJacobianFactorPtr(Ai_G); // JacobianFactor::shared_ptr Ai = convertToJacobianFactorPtr(Ai_G);
// Vector &y = r[i]; // Vector &y = r[i];
// for(JacobianFactor::const_iterator j = Ai->begin(); j != Ai->end(); ++j) { // for(JacobianFactor::const_iterator j = Ai->begin(); j != Ai->end(); ++j) {
@ -416,7 +414,7 @@ namespace gtsam {
{ {
VectorValues x; VectorValues x;
Errors::const_iterator ei = e.begin(); Errors::const_iterator ei = e.begin();
BOOST_FOREACH(const sharedFactor& Ai_G, *this) { for(const sharedFactor& Ai_G: *this) {
JacobianFactor::shared_ptr Ai = convertToJacobianFactorPtr(Ai_G); JacobianFactor::shared_ptr Ai = convertToJacobianFactorPtr(Ai_G);
for(JacobianFactor::const_iterator j = Ai->begin(); j != Ai->end(); ++j) { for(JacobianFactor::const_iterator j = Ai->begin(); j != Ai->end(); ++j) {
// Create the value as a zero vector if it does not exist. // Create the value as a zero vector if it does not exist.
@ -434,7 +432,7 @@ namespace gtsam {
Errors GaussianFactorGraph::gaussianErrors(const VectorValues& x) const Errors GaussianFactorGraph::gaussianErrors(const VectorValues& x) const
{ {
Errors e; Errors e;
BOOST_FOREACH(const sharedFactor& Ai_G, *this) { for(const sharedFactor& Ai_G: *this) {
JacobianFactor::shared_ptr Ai = convertToJacobianFactorPtr(Ai_G); JacobianFactor::shared_ptr Ai = convertToJacobianFactorPtr(Ai_G);
e.push_back(Ai->error_vector(x)); e.push_back(Ai->error_vector(x));
} }

View File

@ -144,7 +144,7 @@ namespace gtsam {
/** unnormalized error */ /** unnormalized error */
double error(const VectorValues& x) const { double error(const VectorValues& x) const {
double total_error = 0.; double total_error = 0.;
BOOST_FOREACH(const sharedFactor& factor, *this){ for(const sharedFactor& factor: *this){
if(factor) if(factor)
total_error += factor->error(x); total_error += factor->error(x);
} }

View File

@ -29,7 +29,6 @@
#include <gtsam/base/ThreadsafeException.h> #include <gtsam/base/ThreadsafeException.h>
#include <gtsam/base/timing.h> #include <gtsam/base/timing.h>
#include <boost/foreach.hpp>
#include <boost/format.hpp> #include <boost/format.hpp>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
@ -241,7 +240,7 @@ HessianFactor::HessianFactor(const GaussianFactorGraph& factors,
keys_.resize(n); keys_.resize(n);
FastVector<DenseIndex> dims(n + 1); FastVector<DenseIndex> dims(n + 1);
DenseIndex slot = 0; DenseIndex slot = 0;
BOOST_FOREACH(const SlotEntry& slotentry, *scatter) { for(const SlotEntry& slotentry: *scatter) {
keys_[slot] = slotentry.key; keys_[slot] = slotentry.key;
dims[slot] = slotentry.dimension; dims[slot] = slotentry.dimension;
++slot; ++slot;
@ -253,7 +252,7 @@ HessianFactor::HessianFactor(const GaussianFactorGraph& factors,
// Form A' * A // Form A' * A
gttic(update); gttic(update);
BOOST_FOREACH(const GaussianFactor::shared_ptr& factor, factors) for(const GaussianFactor::shared_ptr& factor: factors)
if (factor) if (factor)
factor->updateHessian(keys_, &info_); factor->updateHessian(keys_, &info_);
gttoc(update); gttoc(update);

View File

@ -20,7 +20,6 @@
#include <gtsam/linear/GaussianFactorGraph.h> #include <gtsam/linear/GaussianFactorGraph.h>
#include <gtsam/linear/VectorValues.h> #include <gtsam/linear/VectorValues.h>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/foreach.hpp>
#include <iostream> #include <iostream>
using namespace std; using namespace std;
@ -127,7 +126,7 @@ void KeyInfo::initialize(const GaussianFactorGraph &fg) {
/****************************************************************************/ /****************************************************************************/
vector<size_t> KeyInfo::colSpec() const { vector<size_t> KeyInfo::colSpec() const {
std::vector<size_t> result(size(), 0); std::vector<size_t> result(size(), 0);
BOOST_FOREACH ( const KeyInfo::value_type &item, *this ) { for ( const KeyInfo::value_type &item: *this ) {
result[item.second.index()] = item.second.dim(); result[item.second.index()] = item.second.dim();
} }
return result; return result;
@ -136,7 +135,7 @@ vector<size_t> KeyInfo::colSpec() const {
/****************************************************************************/ /****************************************************************************/
VectorValues KeyInfo::x0() const { VectorValues KeyInfo::x0() const {
VectorValues result; VectorValues result;
BOOST_FOREACH ( const KeyInfo::value_type &item, *this ) { for ( const KeyInfo::value_type &item: *this ) {
result.insert(item.first, Vector::Zero(item.second.dim())); result.insert(item.first, Vector::Zero(item.second.dim()));
} }
return result; return result;

View File

@ -32,7 +32,6 @@
#include <gtsam/base/cholesky.h> #include <gtsam/base/cholesky.h>
#include <boost/assign/list_of.hpp> #include <boost/assign/list_of.hpp>
#include <boost/foreach.hpp>
#include <boost/format.hpp> #include <boost/format.hpp>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/array.hpp> #include <boost/array.hpp>
@ -185,12 +184,12 @@ boost::tuple<FastVector<DenseIndex>, DenseIndex, DenseIndex> _countDims(
"Unable to determine dimensionality for all variables"); "Unable to determine dimensionality for all variables");
} }
BOOST_FOREACH(const JacobianFactor::shared_ptr& factor, factors) { for(const JacobianFactor::shared_ptr& factor: factors) {
m += factor->rows(); m += factor->rows();
} }
#ifdef GTSAM_EXTRA_CONSISTENCY_CHECKS #ifdef GTSAM_EXTRA_CONSISTENCY_CHECKS
BOOST_FOREACH(DenseIndex d, varDims) { for(DenseIndex d: varDims) {
assert(d != numeric_limits<DenseIndex>::max()); assert(d != numeric_limits<DenseIndex>::max());
} }
#endif #endif
@ -204,7 +203,7 @@ FastVector<JacobianFactor::shared_ptr> _convertOrCastToJacobians(
gttic(Convert_to_Jacobians); gttic(Convert_to_Jacobians);
FastVector<JacobianFactor::shared_ptr> jacobians; FastVector<JacobianFactor::shared_ptr> jacobians;
jacobians.reserve(factors.size()); jacobians.reserve(factors.size());
BOOST_FOREACH(const GaussianFactor::shared_ptr& factor, factors) { for(const GaussianFactor::shared_ptr& factor: factors) {
if (factor) { if (factor) {
if (JacobianFactor::shared_ptr jf = boost::dynamic_pointer_cast< if (JacobianFactor::shared_ptr jf = boost::dynamic_pointer_cast<
JacobianFactor>(factor)) JacobianFactor>(factor))
@ -262,7 +261,7 @@ JacobianFactor::JacobianFactor(const GaussianFactorGraph& graph,
"The ordering provided to the JacobianFactor combine constructor\n" "The ordering provided to the JacobianFactor combine constructor\n"
"contained extra variables that did not appear in the factors to combine."); "contained extra variables that did not appear in the factors to combine.");
// Add the remaining slots // Add the remaining slots
BOOST_FOREACH(VariableSlots::const_iterator item, unorderedSlots) { for(VariableSlots::const_iterator item: unorderedSlots) {
orderedSlots.push_back(item); orderedSlots.push_back(item);
} }
} else { } else {
@ -292,7 +291,7 @@ JacobianFactor::JacobianFactor(const GaussianFactorGraph& graph,
// Loop over slots in combined factor and copy blocks from source factors // Loop over slots in combined factor and copy blocks from source factors
gttic(copy_blocks); gttic(copy_blocks);
size_t combinedSlot = 0; size_t combinedSlot = 0;
BOOST_FOREACH(VariableSlots::const_iterator varslot, orderedSlots) { for(VariableSlots::const_iterator varslot: orderedSlots) {
JacobianFactor::ABlock destSlot(this->getA(this->begin() + combinedSlot)); JacobianFactor::ABlock destSlot(this->getA(this->begin() + combinedSlot));
// Loop over source jacobians // Loop over source jacobians
DenseIndex nextRow = 0; DenseIndex nextRow = 0;

View File

@ -19,7 +19,6 @@
#include <gtsam/linear/NoiseModel.h> #include <gtsam/linear/NoiseModel.h>
#include <gtsam/base/timing.h> #include <gtsam/base/timing.h>
#include <boost/foreach.hpp>
#include <boost/format.hpp> #include <boost/format.hpp>
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/random/linear_congruential.hpp> #include <boost/random/linear_congruential.hpp>
@ -211,7 +210,7 @@ SharedDiagonal Gaussian::QR(Matrix& Ab) const {
} }
void Gaussian::WhitenSystem(vector<Matrix>& A, Vector& b) const { void Gaussian::WhitenSystem(vector<Matrix>& A, Vector& b) const {
BOOST_FOREACH(Matrix& Aj, A) { WhitenInPlace(Aj); } for(Matrix& Aj: A) { WhitenInPlace(Aj); }
whitenInPlace(b); whitenInPlace(b);
} }
@ -542,7 +541,7 @@ SharedDiagonal Constrained::QR(Matrix& Ab) const {
size_t i = 0; // start with first row size_t i = 0; // start with first row
bool mixed = false; bool mixed = false;
Ab.setZero(); // make sure we don't look below Ab.setZero(); // make sure we don't look below
BOOST_FOREACH (const Triple& t, Rd) { for (const Triple& t: Rd) {
const size_t& j = t.get<0>(); const size_t& j = t.get<0>();
const Matrix& rd = t.get<1>(); const Matrix& rd = t.get<1>();
precisions(i) = t.get<2>(); precisions(i) = t.get<2>();
@ -647,14 +646,14 @@ void Base::reweight(Vector& error) const {
void Base::reweight(vector<Matrix> &A, Vector &error) const { void Base::reweight(vector<Matrix> &A, Vector &error) const {
if ( reweight_ == Block ) { if ( reweight_ == Block ) {
const double w = sqrtWeight(error.norm()); const double w = sqrtWeight(error.norm());
BOOST_FOREACH(Matrix& Aj, A) { for(Matrix& Aj: A) {
Aj *= w; Aj *= w;
} }
error *= w; error *= w;
} }
else { else {
const Vector W = sqrtWeight(error); const Vector W = sqrtWeight(error);
BOOST_FOREACH(Matrix& Aj, A) { for(Matrix& Aj: A) {
vector_scale_inplace(W,Aj); vector_scale_inplace(W,Aj);
} }
error = W.cwiseProduct(error); error = W.cwiseProduct(error);

View File

@ -22,7 +22,6 @@
#include <gtsam/linear/Preconditioner.h> #include <gtsam/linear/Preconditioner.h>
#include <gtsam/linear/VectorValues.h> #include <gtsam/linear/VectorValues.h>
#include <boost/foreach.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <algorithm> #include <algorithm>
@ -150,7 +149,7 @@ VectorValues buildVectorValues(const Vector &v, const Ordering &ordering,
/**********************************************************************************/ /**********************************************************************************/
VectorValues buildVectorValues(const Vector &v, const KeyInfo &keyInfo) { VectorValues buildVectorValues(const Vector &v, const KeyInfo &keyInfo) {
VectorValues result; VectorValues result;
BOOST_FOREACH ( const KeyInfo::value_type &item, keyInfo ) { for ( const KeyInfo::value_type &item: keyInfo ) {
result.insert(item.first, result.insert(item.first,
v.segment(item.second.colstart(), item.second.dim())); v.segment(item.second.colstart(), item.second.dim()));
} }

View File

@ -145,7 +145,7 @@ void BlockJacobiPreconditioner::build(
/* getting the block diagonals over the factors */ /* getting the block diagonals over the factors */
std::map<Key, Matrix> hessianMap =gfg.hessianBlockDiagonal(); std::map<Key, Matrix> hessianMap =gfg.hessianBlockDiagonal();
BOOST_FOREACH ( const Matrix hessian, hessianMap | boost::adaptors::map_values) for ( const Matrix hessian: hessianMap | boost::adaptors::map_values)
blocks.push_back(hessian); blocks.push_back(hessian);
/* if necessary, allocating the memory for cacheing the factorization results */ /* if necessary, allocating the memory for cacheing the factorization results */

View File

@ -20,7 +20,6 @@
#include <gtsam/linear/HessianFactor.h> #include <gtsam/linear/HessianFactor.h>
#include <gtsam/linear/RegularJacobianFactor.h> #include <gtsam/linear/RegularJacobianFactor.h>
#include <boost/foreach.hpp>
#include <vector> #include <vector>
namespace gtsam { namespace gtsam {
@ -114,7 +113,7 @@ public:
double* yvalues) const { double* yvalues) const {
// Create a vector of temporary y_ values, corresponding to rows i // Create a vector of temporary y_ values, corresponding to rows i
y_.resize(size()); y_.resize(size());
BOOST_FOREACH(VectorD & yi, y_) for(VectorD & yi: y_)
yi.setZero(); yi.setZero();
// Accessing the VectorValues one by one is expensive // Accessing the VectorValues one by one is expensive
@ -147,7 +146,7 @@ public:
// Create a vector of temporary y_ values, corresponding to rows i // Create a vector of temporary y_ values, corresponding to rows i
y_.resize(size()); y_.resize(size());
BOOST_FOREACH(VectorD & yi, y_) for(VectorD & yi: y_)
yi.setZero(); yi.setZero();
// Accessing the VectorValues one by one is expensive // Accessing the VectorValues one by one is expensive

View File

@ -20,7 +20,6 @@
#include <gtsam/linear/JacobianFactor.h> #include <gtsam/linear/JacobianFactor.h>
#include <gtsam/linear/VectorValues.h> #include <gtsam/linear/VectorValues.h>
#include <boost/foreach.hpp>
namespace gtsam { namespace gtsam {

View File

@ -20,7 +20,6 @@
#include <gtsam/linear/Scatter.h> #include <gtsam/linear/Scatter.h>
#include <gtsam/inference/Ordering.h> #include <gtsam/inference/Ordering.h>
#include <boost/foreach.hpp>
#include <algorithm> #include <algorithm>
using namespace std; using namespace std;
@ -41,13 +40,13 @@ Scatter::Scatter(const GaussianFactorGraph& gfg,
// If we have an ordering, pre-fill the ordered variables first // If we have an ordering, pre-fill the ordered variables first
if (ordering) { if (ordering) {
BOOST_FOREACH (Key key, *ordering) { for (Key key: *ordering) {
push_back(SlotEntry(key, 0)); push_back(SlotEntry(key, 0));
} }
} }
// Now, find dimensions of variables and/or extend // Now, find dimensions of variables and/or extend
BOOST_FOREACH (const GaussianFactor::shared_ptr& factor, gfg) { for (const GaussianFactor::shared_ptr& factor: gfg) {
if (!factor) continue; if (!factor) continue;
// TODO: Fix this hack to cope with zero-row Jacobians that come from BayesTreeOrphanWrappers // TODO: Fix this hack to cope with zero-row Jacobians that come from BayesTreeOrphanWrappers

View File

@ -32,7 +32,7 @@
#include <boost/archive/text_iarchive.hpp> #include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/vector.hpp> #include <boost/serialization/vector.hpp>
#include <boost/foreach.hpp> #include <boost/range/adaptor/reversed.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <algorithm> #include <algorithm>
@ -59,7 +59,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
static GaussianFactorGraph::shared_ptr convertToJacobianFactors(const GaussianFactorGraph &gfg) { static GaussianFactorGraph::shared_ptr convertToJacobianFactors(const GaussianFactorGraph &gfg) {
GaussianFactorGraph::shared_ptr result(new GaussianFactorGraph()); GaussianFactorGraph::shared_ptr result(new GaussianFactorGraph());
BOOST_FOREACH(const GaussianFactor::shared_ptr &gf, gfg) { for(const GaussianFactor::shared_ptr &gf: gfg) {
JacobianFactor::shared_ptr jf = boost::dynamic_pointer_cast<JacobianFactor>(gf); JacobianFactor::shared_ptr jf = boost::dynamic_pointer_cast<JacobianFactor>(gf);
if( !jf ) { if( !jf ) {
jf = boost::make_shared<JacobianFactor>(*gf); // Convert any non-Jacobian factors to Jacobians (e.g. Hessian -> Jacobian with Cholesky) jf = boost::make_shared<JacobianFactor>(*gf); // Convert any non-Jacobian factors to Jacobians (e.g. Hessian -> Jacobian with Cholesky)
@ -122,7 +122,7 @@ vector<size_t> uniqueSampler(const vector<double> &weight, const size_t n) {
/* sampling and cache results */ /* sampling and cache results */
vector<size_t> samples = iidSampler(localWeights, n-count); vector<size_t> samples = iidSampler(localWeights, n-count);
BOOST_FOREACH ( const size_t &id, samples ) { for ( const size_t &id: samples ) {
if ( touched[id] == false ) { if ( touched[id] == false ) {
touched[id] = true ; touched[id] = true ;
result.push_back(id); result.push_back(id);
@ -136,7 +136,7 @@ vector<size_t> uniqueSampler(const vector<double> &weight, const size_t n) {
/****************************************************************************/ /****************************************************************************/
Subgraph::Subgraph(const std::vector<size_t> &indices) { Subgraph::Subgraph(const std::vector<size_t> &indices) {
edges_.reserve(indices.size()); edges_.reserve(indices.size());
BOOST_FOREACH ( const size_t &idx, indices ) { for ( const size_t &idx: indices ) {
edges_.push_back(SubgraphEdge(idx, 1.0)); edges_.push_back(SubgraphEdge(idx, 1.0));
} }
} }
@ -144,7 +144,7 @@ Subgraph::Subgraph(const std::vector<size_t> &indices) {
/****************************************************************************/ /****************************************************************************/
std::vector<size_t> Subgraph::edgeIndices() const { std::vector<size_t> Subgraph::edgeIndices() const {
std::vector<size_t> eid; eid.reserve(size()); std::vector<size_t> eid; eid.reserve(size());
BOOST_FOREACH ( const SubgraphEdge &edge, edges_ ) { for ( const SubgraphEdge &edge: edges_ ) {
eid.push_back(edge.index_); eid.push_back(edge.index_);
} }
return eid; return eid;
@ -180,7 +180,7 @@ std::ostream &operator<<(std::ostream &os, const SubgraphEdge &edge) {
/****************************************************************************/ /****************************************************************************/
std::ostream &operator<<(std::ostream &os, const Subgraph &subgraph) { std::ostream &operator<<(std::ostream &os, const Subgraph &subgraph) {
os << "Subgraph" << endl; os << "Subgraph" << endl;
BOOST_FOREACH ( const SubgraphEdge &e, subgraph.edges() ) { for ( const SubgraphEdge &e: subgraph.edges() ) {
os << e << ", " ; os << e << ", " ;
} }
return os; return os;
@ -286,7 +286,7 @@ std::vector<size_t> SubgraphBuilder::buildTree(const GaussianFactorGraph &gfg, c
std::vector<size_t> SubgraphBuilder::unary(const GaussianFactorGraph &gfg) const { std::vector<size_t> SubgraphBuilder::unary(const GaussianFactorGraph &gfg) const {
std::vector<size_t> result ; std::vector<size_t> result ;
size_t idx = 0; size_t idx = 0;
BOOST_FOREACH ( const GaussianFactor::shared_ptr &gf, gfg ) { for ( const GaussianFactor::shared_ptr &gf: gfg ) {
if ( gf->size() == 1 ) { if ( gf->size() == 1 ) {
result.push_back(idx); result.push_back(idx);
} }
@ -299,7 +299,7 @@ std::vector<size_t> SubgraphBuilder::unary(const GaussianFactorGraph &gfg) const
std::vector<size_t> SubgraphBuilder::natural_chain(const GaussianFactorGraph &gfg) const { std::vector<size_t> SubgraphBuilder::natural_chain(const GaussianFactorGraph &gfg) const {
std::vector<size_t> result ; std::vector<size_t> result ;
size_t idx = 0; size_t idx = 0;
BOOST_FOREACH ( const GaussianFactor::shared_ptr &gf, gfg ) { for ( const GaussianFactor::shared_ptr &gf: gfg ) {
if ( gf->size() == 2 ) { if ( gf->size() == 2 ) {
const Key k0 = gf->keys()[0], k1 = gf->keys()[1]; const Key k0 = gf->keys()[0], k1 = gf->keys()[1];
if ( (k1-k0) == 1 || (k0-k1) == 1 ) if ( (k1-k0) == 1 || (k0-k1) == 1 )
@ -332,9 +332,9 @@ std::vector<size_t> SubgraphBuilder::bfs(const GaussianFactorGraph &gfg) const {
/* traversal */ /* traversal */
while ( !q.empty() ) { while ( !q.empty() ) {
const size_t head = q.front(); q.pop(); const size_t head = q.front(); q.pop();
BOOST_FOREACH ( const size_t id, variableIndex[head] ) { for ( const size_t id: variableIndex[head] ) {
const GaussianFactor &gf = *gfg[id]; const GaussianFactor &gf = *gfg[id];
BOOST_FOREACH ( const size_t key, gf.keys() ) { for ( const size_t key: gf.keys() ) {
if ( flags.count(key) == 0 ) { if ( flags.count(key) == 0 ) {
q.push(key); q.push(key);
flags.insert(key); flags.insert(key);
@ -360,7 +360,7 @@ std::vector<size_t> SubgraphBuilder::kruskal(const GaussianFactorGraph &gfg, con
DSFVector D(n) ; DSFVector D(n) ;
size_t count = 0 ; double sum = 0.0 ; size_t count = 0 ; double sum = 0.0 ;
BOOST_FOREACH (const size_t id, idx) { for (const size_t id: idx) {
const GaussianFactor &gf = *gfg[id]; const GaussianFactor &gf = *gfg[id];
if ( gf.keys().size() != 2 ) continue; if ( gf.keys().size() != 2 ) continue;
const size_t u = ordering.find(gf.keys()[0])->second, const size_t u = ordering.find(gf.keys()[0])->second,
@ -399,7 +399,7 @@ Subgraph::shared_ptr SubgraphBuilder::operator() (const GaussianFactorGraph &gfg
} }
/* down weight the tree edges to zero */ /* down weight the tree edges to zero */
BOOST_FOREACH ( const size_t id, tree ) { for ( const size_t id: tree ) {
w[id] = 0.0; w[id] = 0.0;
} }
@ -419,7 +419,7 @@ SubgraphBuilder::Weights SubgraphBuilder::weights(const GaussianFactorGraph &gfg
const size_t m = gfg.size() ; const size_t m = gfg.size() ;
Weights weight; weight.reserve(m); Weights weight; weight.reserve(m);
BOOST_FOREACH(const GaussianFactor::shared_ptr &gf, gfg ) { for(const GaussianFactor::shared_ptr &gf: gfg ) {
switch ( parameters_.skeletonWeight_ ) { switch ( parameters_.skeletonWeight_ ) {
case SubgraphBuilderParameters::EQUAL: case SubgraphBuilderParameters::EQUAL:
weight.push_back(1.0); weight.push_back(1.0);
@ -569,7 +569,7 @@ void SubgraphPreconditioner::solve(const Vector& y, Vector &x) const
std::copy(y.data(), y.data() + y.rows(), x.data()); std::copy(y.data(), y.data() + y.rows(), x.data());
/* in place back substitute */ /* in place back substitute */
BOOST_REVERSE_FOREACH(const boost::shared_ptr<GaussianConditional> & cg, *Rc1_) { for (auto cg: boost::adaptors::reverse(*Rc1_)) {
/* collect a subvector of x that consists of the parents of cg (S) */ /* collect a subvector of x that consists of the parents of cg (S) */
const Vector xParent = getSubvector(x, keyInfo_, FastVector<Key>(cg->beginParents(), cg->endParents())); const Vector xParent = getSubvector(x, keyInfo_, FastVector<Key>(cg->beginParents(), cg->endParents()));
const Vector rhsFrontal = getSubvector(x, keyInfo_, FastVector<Key>(cg->beginFrontals(), cg->endFrontals())); const Vector rhsFrontal = getSubvector(x, keyInfo_, FastVector<Key>(cg->beginFrontals(), cg->endFrontals()));
@ -589,7 +589,7 @@ void SubgraphPreconditioner::transposeSolve(const Vector& y, Vector& x) const
std::copy(y.data(), y.data() + y.rows(), x.data()); std::copy(y.data(), y.data() + y.rows(), x.data());
/* in place back substitute */ /* in place back substitute */
BOOST_FOREACH(const boost::shared_ptr<GaussianConditional> & cg, *Rc1_) { for(const boost::shared_ptr<GaussianConditional> & cg: *Rc1_) {
const Vector rhsFrontal = getSubvector(x, keyInfo_, FastVector<Key>(cg->beginFrontals(), cg->endFrontals())); const Vector rhsFrontal = getSubvector(x, keyInfo_, FastVector<Key>(cg->beginFrontals(), cg->endFrontals()));
// const Vector solFrontal = cg->get_R().triangularView<Eigen::Upper>().transpose().solve(rhsFrontal); // const Vector solFrontal = cg->get_R().triangularView<Eigen::Upper>().transpose().solve(rhsFrontal);
const Vector solFrontal = cg->get_R().transpose().triangularView<Eigen::Lower>().solve(rhsFrontal); const Vector solFrontal = cg->get_R().transpose().triangularView<Eigen::Lower>().solve(rhsFrontal);
@ -634,7 +634,7 @@ Vector getSubvector(const Vector &src, const KeyInfo &keyInfo, const FastVector<
/* figure out dimension by traversing the keys */ /* figure out dimension by traversing the keys */
size_t d = 0; size_t d = 0;
BOOST_FOREACH ( const Key &key, keys ) { for ( const Key &key: keys ) {
const KeyInfoEntry &entry = keyInfo.find(key)->second; const KeyInfoEntry &entry = keyInfo.find(key)->second;
cache.push_back(make_pair(entry.colstart(), entry.dim())); cache.push_back(make_pair(entry.colstart(), entry.dim()));
d += entry.dim(); d += entry.dim();
@ -643,7 +643,7 @@ Vector getSubvector(const Vector &src, const KeyInfo &keyInfo, const FastVector<
/* use the cache to fill the result */ /* use the cache to fill the result */
Vector result = Vector::Zero(d, 1); Vector result = Vector::Zero(d, 1);
size_t idx = 0; size_t idx = 0;
BOOST_FOREACH ( const Cache::value_type &p, cache ) { for ( const Cache::value_type &p: cache ) {
result.segment(idx, p.second) = src.segment(p.first, p.second) ; result.segment(idx, p.second) = src.segment(p.first, p.second) ;
idx += p.second; idx += p.second;
} }
@ -655,7 +655,7 @@ Vector getSubvector(const Vector &src, const KeyInfo &keyInfo, const FastVector<
void setSubvector(const Vector &src, const KeyInfo &keyInfo, const FastVector<Key> &keys, Vector &dst) { void setSubvector(const Vector &src, const KeyInfo &keyInfo, const FastVector<Key> &keys, Vector &dst) {
/* use the cache */ /* use the cache */
size_t idx = 0; size_t idx = 0;
BOOST_FOREACH ( const Key &key, keys ) { for ( const Key &key: keys ) {
const KeyInfoEntry &entry = keyInfo.find(key)->second; const KeyInfoEntry &entry = keyInfo.find(key)->second;
dst.segment(entry.colstart(), entry.dim()) = src.segment(idx, entry.dim()) ; dst.segment(entry.colstart(), entry.dim()) = src.segment(idx, entry.dim()) ;
idx += entry.dim(); idx += entry.dim();
@ -668,7 +668,7 @@ buildFactorSubgraph(const GaussianFactorGraph &gfg, const Subgraph &subgraph, co
GaussianFactorGraph::shared_ptr result(new GaussianFactorGraph()); GaussianFactorGraph::shared_ptr result(new GaussianFactorGraph());
result->reserve(subgraph.size()); result->reserve(subgraph.size());
BOOST_FOREACH ( const SubgraphEdge &e, subgraph ) { for ( const SubgraphEdge &e: subgraph ) {
const size_t idx = e.index(); const size_t idx = e.index();
if ( clone ) result->push_back(gfg[idx]->clone()); if ( clone ) result->push_back(gfg[idx]->clone());
else result->push_back(gfg[idx]); else result->push_back(gfg[idx]);

View File

@ -131,7 +131,7 @@ SubgraphSolver::splitGraph(const GaussianFactorGraph &jfg) {
GaussianFactorGraph::shared_ptr Ac(new GaussianFactorGraph()); GaussianFactorGraph::shared_ptr Ac(new GaussianFactorGraph());
size_t t = 0; size_t t = 0;
BOOST_FOREACH ( const GaussianFactor::shared_ptr &gf, jfg ) { for ( const GaussianFactor::shared_ptr &gf: jfg ) {
if (gf->keys().size() > 2) { if (gf->keys().size() > 2) {
throw runtime_error( throw runtime_error(

View File

@ -18,7 +18,6 @@
#include <gtsam/linear/VectorValues.h> #include <gtsam/linear/VectorValues.h>
#include <boost/foreach.hpp>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/range/combine.hpp> #include <boost/range/combine.hpp>
#include <boost/range/numeric.hpp> #include <boost/range/numeric.hpp>
@ -48,7 +47,7 @@ namespace gtsam {
VectorValues::VectorValues(const Vector& x, const Dims& dims) { VectorValues::VectorValues(const Vector& x, const Dims& dims) {
typedef pair<Key, size_t> Pair; typedef pair<Key, size_t> Pair;
size_t j = 0; size_t j = 0;
BOOST_FOREACH(const Pair& v, dims) { for(const Pair& v: dims) {
Key key; Key key;
size_t n; size_t n;
boost::tie(key, n) = v; boost::tie(key, n) = v;
@ -61,7 +60,7 @@ namespace gtsam {
VectorValues VectorValues::Zero(const VectorValues& other) VectorValues VectorValues::Zero(const VectorValues& other)
{ {
VectorValues result; VectorValues result;
BOOST_FOREACH(const KeyValuePair& v, other) for(const KeyValuePair& v: other)
result.values_.insert(make_pair(v.first, Vector::Zero(v.second.size()))); result.values_.insert(make_pair(v.first, Vector::Zero(v.second.size())));
return result; return result;
} }
@ -82,7 +81,7 @@ namespace gtsam {
void VectorValues::update(const VectorValues& values) void VectorValues::update(const VectorValues& values)
{ {
iterator hint = begin(); iterator hint = begin();
BOOST_FOREACH(const KeyValuePair& key_value, values) for(const KeyValuePair& key_value: values)
{ {
// Use this trick to find the value using a hint, since we are inserting from another sorted map // Use this trick to find the value using a hint, since we are inserting from another sorted map
size_t oldSize = values_.size(); size_t oldSize = values_.size();
@ -108,14 +107,14 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
void VectorValues::setZero() void VectorValues::setZero()
{ {
BOOST_FOREACH(Vector& v, values_ | map_values) for(Vector& v: values_ | map_values)
v.setZero(); v.setZero();
} }
/* ************************************************************************* */ /* ************************************************************************* */
void VectorValues::print(const string& str, const KeyFormatter& formatter) const { void VectorValues::print(const string& str, const KeyFormatter& formatter) const {
cout << str << ": " << size() << " elements\n"; cout << str << ": " << size() << " elements\n";
BOOST_FOREACH(const value_type& key_value, *this) for(const value_type& key_value: *this)
cout << " " << formatter(key_value.first) << ": " << key_value.second.transpose() << "\n"; cout << " " << formatter(key_value.first) << ": " << key_value.second.transpose() << "\n";
cout.flush(); cout.flush();
} }
@ -125,7 +124,7 @@ namespace gtsam {
if(this->size() != x.size()) if(this->size() != x.size())
return false; return false;
typedef boost::tuple<value_type, value_type> ValuePair; typedef boost::tuple<value_type, value_type> ValuePair;
BOOST_FOREACH(const ValuePair& values, boost::combine(*this, x)) { for(const ValuePair& values: boost::combine(*this, x)) {
if(values.get<0>().first != values.get<1>().first || if(values.get<0>().first != values.get<1>().first ||
!equal_with_abs_tol(values.get<0>().second, values.get<1>().second, tol)) !equal_with_abs_tol(values.get<0>().second, values.get<1>().second, tol))
return false; return false;
@ -138,13 +137,13 @@ namespace gtsam {
{ {
// Count dimensions // Count dimensions
DenseIndex totalDim = 0; DenseIndex totalDim = 0;
BOOST_FOREACH(const Vector& v, *this | map_values) for(const Vector& v: *this | map_values)
totalDim += v.size(); totalDim += v.size();
// Copy vectors // Copy vectors
Vector result(totalDim); Vector result(totalDim);
DenseIndex pos = 0; DenseIndex pos = 0;
BOOST_FOREACH(const Vector& v, *this | map_values) { for(const Vector& v: *this | map_values) {
result.segment(pos, v.size()) = v; result.segment(pos, v.size()) = v;
pos += v.size(); pos += v.size();
} }
@ -166,7 +165,7 @@ namespace gtsam {
// Copy vectors // Copy vectors
Vector result(totalDim); Vector result(totalDim);
DenseIndex pos = 0; DenseIndex pos = 0;
BOOST_FOREACH(const Vector *v, items) { for(const Vector *v: items) {
result.segment(pos, v->size()) = *v; result.segment(pos, v->size()) = *v;
pos += v->size(); pos += v->size();
} }
@ -179,11 +178,11 @@ namespace gtsam {
{ {
// Count dimensions // Count dimensions
DenseIndex totalDim = 0; DenseIndex totalDim = 0;
BOOST_FOREACH(size_t dim, keys | map_values) for(size_t dim: keys | map_values)
totalDim += dim; totalDim += dim;
Vector result(totalDim); Vector result(totalDim);
size_t j = 0; size_t j = 0;
BOOST_FOREACH(const Dims::value_type& it, keys) { for(const Dims::value_type& it: keys) {
result.segment(j,it.second) = at(it.first); result.segment(j,it.second) = at(it.first);
j += it.second; j += it.second;
} }
@ -221,7 +220,7 @@ namespace gtsam {
double result = 0.0; double result = 0.0;
typedef boost::tuple<value_type, value_type> ValuePair; typedef boost::tuple<value_type, value_type> ValuePair;
using boost::adaptors::map_values; using boost::adaptors::map_values;
BOOST_FOREACH(const ValuePair& values, boost::combine(*this, v)) { for(const ValuePair& values: boost::combine(*this, v)) {
assert_throw(values.get<0>().first == values.get<1>().first, assert_throw(values.get<0>().first == values.get<1>().first,
invalid_argument("VectorValues::dot called with a VectorValues of different structure")); invalid_argument("VectorValues::dot called with a VectorValues of different structure"));
assert_throw(values.get<0>().second.size() == values.get<1>().second.size(), assert_throw(values.get<0>().second.size() == values.get<1>().second.size(),
@ -240,7 +239,7 @@ namespace gtsam {
double VectorValues::squaredNorm() const { double VectorValues::squaredNorm() const {
double sumSquares = 0.0; double sumSquares = 0.0;
using boost::adaptors::map_values; using boost::adaptors::map_values;
BOOST_FOREACH(const Vector& v, *this | map_values) for(const Vector& v: *this | map_values)
sumSquares += v.squaredNorm(); sumSquares += v.squaredNorm();
return sumSquares; return sumSquares;
} }
@ -329,7 +328,7 @@ namespace gtsam {
VectorValues operator*(const double a, const VectorValues &v) VectorValues operator*(const double a, const VectorValues &v)
{ {
VectorValues result; VectorValues result;
BOOST_FOREACH(const VectorValues::KeyValuePair& key_v, v) for(const VectorValues::KeyValuePair& key_v: v)
result.values_.insert(result.values_.end(), make_pair(key_v.first, a * key_v.second)); result.values_.insert(result.values_.end(), make_pair(key_v.first, a * key_v.second));
return result; return result;
} }
@ -343,7 +342,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
VectorValues& VectorValues::operator*=(double alpha) VectorValues& VectorValues::operator*=(double alpha)
{ {
BOOST_FOREACH(Vector& v, *this | map_values) for(Vector& v: *this | map_values)
v *= alpha; v *= alpha;
return *this; return *this;
} }

View File

@ -55,7 +55,7 @@ namespace gtsam
OptimizeData myData; OptimizeData myData;
myData.parentData = parentData; myData.parentData = parentData;
// Take any ancestor results we'll need // Take any ancestor results we'll need
BOOST_FOREACH(Key parent, clique->conditional_->parents()) for(Key parent: clique->conditional_->parents())
myData.cliqueResults.insert(std::make_pair(parent, myData.parentData->cliqueResults.at(parent))); myData.cliqueResults.insert(std::make_pair(parent, myData.parentData->cliqueResults.at(parent)));
// Solve and store in our results // Solve and store in our results
//collectedResult.insert(clique->conditional()->solve(collectedResult/*myData.ancestorResults*/)); //collectedResult.insert(clique->conditional()->solve(collectedResult/*myData.ancestorResults*/));
@ -68,7 +68,7 @@ namespace gtsam
DenseIndex dim = 0; DenseIndex dim = 0;
FastVector<VectorValues::const_iterator> parentPointers; FastVector<VectorValues::const_iterator> parentPointers;
parentPointers.reserve(clique->conditional()->nrParents()); parentPointers.reserve(clique->conditional()->nrParents());
BOOST_FOREACH(Key parent, clique->conditional()->parents()) { for(Key parent: clique->conditional()->parents()) {
parentPointers.push_back(myData.cliqueResults.at(parent)); parentPointers.push_back(myData.cliqueResults.at(parent));
dim += parentPointers.back()->second.size(); dim += parentPointers.back()->second.size();
} }
@ -76,7 +76,7 @@ namespace gtsam
// Fill parent vector // Fill parent vector
xS.resize(dim); xS.resize(dim);
DenseIndex vectorPos = 0; DenseIndex vectorPos = 0;
BOOST_FOREACH(const VectorValues::const_iterator& parentPointer, parentPointers) { for(const VectorValues::const_iterator& parentPointer: parentPointers) {
const Vector& parentVector = parentPointer->second; const Vector& parentVector = parentPointer->second;
xS.block(vectorPos,0,parentVector.size(),1) = parentVector.block(0,0,parentVector.size(),1); xS.block(vectorPos,0,parentVector.size(),1) = parentVector.block(0,0,parentVector.size(),1);
vectorPos += parentVector.size(); vectorPos += parentVector.size();
@ -108,7 +108,7 @@ namespace gtsam
// OptimizeData myData; // OptimizeData myData;
// myData.parentData = parentData; // myData.parentData = parentData;
// // Take any ancestor results we'll need // // Take any ancestor results we'll need
// BOOST_FOREACH(Key parent, clique->conditional_->parents()) // for(Key parent: clique->conditional_->parents())
// myData.ancestorResults.insert(parent, myData.parentData->ancestorResults[parent]); // myData.ancestorResults.insert(parent, myData.parentData->ancestorResults[parent]);
// // Solve and store in our results // // Solve and store in our results
// myData.results.insert(clique->conditional()->solve(myData.ancestorResults)); // myData.results.insert(clique->conditional()->solve(myData.ancestorResults));

View File

@ -30,7 +30,6 @@ using namespace boost::assign;
#include <sstream> #include <sstream>
#include <CppUnitLite/TestHarness.h> #include <CppUnitLite/TestHarness.h>
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp>
using namespace std; using namespace std;
using namespace gtsam; using namespace gtsam;

View File

@ -22,7 +22,6 @@
#include <CppUnitLite/TestHarness.h> #include <CppUnitLite/TestHarness.h>
#include <boost/foreach.hpp>
#include <boost/assign/std/vector.hpp> #include <boost/assign/std/vector.hpp>
#include <iostream> #include <iostream>
@ -58,32 +57,32 @@ TEST(NoiseModel, constructors)
m.push_back(Isotropic::Precision(3, prc,false)); m.push_back(Isotropic::Precision(3, prc,false));
// test kSigmas // test kSigmas
BOOST_FOREACH(Gaussian::shared_ptr mi, m) for(Gaussian::shared_ptr mi: m)
EXPECT(assert_equal(kSigmas,mi->sigmas())); EXPECT(assert_equal(kSigmas,mi->sigmas()));
// test whiten // test whiten
BOOST_FOREACH(Gaussian::shared_ptr mi, m) for(Gaussian::shared_ptr mi: m)
EXPECT(assert_equal(whitened,mi->whiten(unwhitened))); EXPECT(assert_equal(whitened,mi->whiten(unwhitened)));
// test unwhiten // test unwhiten
BOOST_FOREACH(Gaussian::shared_ptr mi, m) for(Gaussian::shared_ptr mi: m)
EXPECT(assert_equal(unwhitened,mi->unwhiten(whitened))); EXPECT(assert_equal(unwhitened,mi->unwhiten(whitened)));
// test Mahalanobis distance // test Mahalanobis distance
double distance = 5*5+10*10+15*15; double distance = 5*5+10*10+15*15;
BOOST_FOREACH(Gaussian::shared_ptr mi, m) for(Gaussian::shared_ptr mi: m)
DOUBLES_EQUAL(distance,mi->Mahalanobis(unwhitened),1e-9); DOUBLES_EQUAL(distance,mi->Mahalanobis(unwhitened),1e-9);
// test R matrix // test R matrix
BOOST_FOREACH(Gaussian::shared_ptr mi, m) for(Gaussian::shared_ptr mi: m)
EXPECT(assert_equal(R,mi->R())); EXPECT(assert_equal(R,mi->R()));
// test covariance // test covariance
BOOST_FOREACH(Gaussian::shared_ptr mi, m) for(Gaussian::shared_ptr mi: m)
EXPECT(assert_equal(kCovariance,mi->covariance())); EXPECT(assert_equal(kCovariance,mi->covariance()));
// test covariance // test covariance
BOOST_FOREACH(Gaussian::shared_ptr mi, m) for(Gaussian::shared_ptr mi: m)
EXPECT(assert_equal(kCovariance.inverse(),mi->information())); EXPECT(assert_equal(kCovariance.inverse(),mi->information()));
// test Whiten operator // test Whiten operator
@ -92,7 +91,7 @@ TEST(NoiseModel, constructors)
0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0,
1.0, 0.0, 0.0, 1.0).finished()); 1.0, 0.0, 0.0, 1.0).finished());
Matrix expected = kInverseSigma * H; Matrix expected = kInverseSigma * H;
BOOST_FOREACH(Gaussian::shared_ptr mi, m) for(Gaussian::shared_ptr mi: m)
EXPECT(assert_equal(expected,mi->Whiten(H))); EXPECT(assert_equal(expected,mi->Whiten(H)));
// can only test inplace version once :-) // can only test inplace version once :-)

View File

@ -93,7 +93,7 @@ void ISAM2::Impl::RemoveVariables(const KeySet& unusedKeys, const FastVector<ISA
KeySet& fixedVariables) KeySet& fixedVariables)
{ {
variableIndex.removeUnusedVariables(unusedKeys.begin(), unusedKeys.end()); variableIndex.removeUnusedVariables(unusedKeys.begin(), unusedKeys.end());
BOOST_FOREACH(Key key, unusedKeys) { for(Key key: unusedKeys) {
delta.erase(key); delta.erase(key);
deltaNewton.erase(key); deltaNewton.erase(key);
RgProd.erase(key); RgProd.erase(key);
@ -112,7 +112,7 @@ KeySet ISAM2::Impl::CheckRelinearizationFull(const VectorValues& delta,
if(const double* threshold = boost::get<double>(&relinearizeThreshold)) if(const double* threshold = boost::get<double>(&relinearizeThreshold))
{ {
BOOST_FOREACH(const VectorValues::KeyValuePair& key_delta, delta) { for(const VectorValues::KeyValuePair& key_delta: delta) {
double maxDelta = key_delta.second.lpNorm<Eigen::Infinity>(); double maxDelta = key_delta.second.lpNorm<Eigen::Infinity>();
if(maxDelta >= *threshold) if(maxDelta >= *threshold)
relinKeys.insert(key_delta.first); relinKeys.insert(key_delta.first);
@ -120,7 +120,7 @@ KeySet ISAM2::Impl::CheckRelinearizationFull(const VectorValues& delta,
} }
else if(const FastMap<char,Vector>* thresholds = boost::get<FastMap<char,Vector> >(&relinearizeThreshold)) else if(const FastMap<char,Vector>* thresholds = boost::get<FastMap<char,Vector> >(&relinearizeThreshold))
{ {
BOOST_FOREACH(const VectorValues::KeyValuePair& key_delta, delta) { for(const VectorValues::KeyValuePair& key_delta: delta) {
const Vector& threshold = thresholds->find(Symbol(key_delta.first).chr())->second; const Vector& threshold = thresholds->find(Symbol(key_delta.first).chr())->second;
if(threshold.rows() != key_delta.second.rows()) if(threshold.rows() != key_delta.second.rows())
throw std::invalid_argument("Relinearization threshold vector dimensionality for '" + std::string(1, Symbol(key_delta.first).chr()) + "' passed into iSAM2 parameters does not match actual variable dimensionality."); throw std::invalid_argument("Relinearization threshold vector dimensionality for '" + std::string(1, Symbol(key_delta.first).chr()) + "' passed into iSAM2 parameters does not match actual variable dimensionality.");
@ -138,7 +138,7 @@ void CheckRelinearizationRecursiveDouble(KeySet& relinKeys, double threshold,
{ {
// Check the current clique for relinearization // Check the current clique for relinearization
bool relinearize = false; bool relinearize = false;
BOOST_FOREACH(Key var, *clique->conditional()) { for(Key var: *clique->conditional()) {
double maxDelta = delta[var].lpNorm<Eigen::Infinity>(); double maxDelta = delta[var].lpNorm<Eigen::Infinity>();
if(maxDelta >= threshold) { if(maxDelta >= threshold) {
relinKeys.insert(var); relinKeys.insert(var);
@ -148,7 +148,7 @@ void CheckRelinearizationRecursiveDouble(KeySet& relinKeys, double threshold,
// If this node was relinearized, also check its children // If this node was relinearized, also check its children
if(relinearize) { if(relinearize) {
BOOST_FOREACH(const ISAM2Clique::shared_ptr& child, clique->children) { for(const ISAM2Clique::shared_ptr& child: clique->children) {
CheckRelinearizationRecursiveDouble(relinKeys, threshold, delta, child); CheckRelinearizationRecursiveDouble(relinKeys, threshold, delta, child);
} }
} }
@ -161,7 +161,7 @@ void CheckRelinearizationRecursiveMap(KeySet& relinKeys, const FastMap<char,Vect
{ {
// Check the current clique for relinearization // Check the current clique for relinearization
bool relinearize = false; bool relinearize = false;
BOOST_FOREACH(Key var, *clique->conditional()) { for(Key var: *clique->conditional()) {
// Find the threshold for this variable type // Find the threshold for this variable type
const Vector& threshold = thresholds.find(Symbol(var).chr())->second; const Vector& threshold = thresholds.find(Symbol(var).chr())->second;
@ -180,7 +180,7 @@ void CheckRelinearizationRecursiveMap(KeySet& relinKeys, const FastMap<char,Vect
// If this node was relinearized, also check its children // If this node was relinearized, also check its children
if(relinearize) { if(relinearize) {
BOOST_FOREACH(const ISAM2Clique::shared_ptr& child, clique->children) { for(const ISAM2Clique::shared_ptr& child: clique->children) {
CheckRelinearizationRecursiveMap(relinKeys, thresholds, delta, child); CheckRelinearizationRecursiveMap(relinKeys, thresholds, delta, child);
} }
} }
@ -192,7 +192,7 @@ KeySet ISAM2::Impl::CheckRelinearizationPartial(const FastVector<ISAM2::sharedCl
const ISAM2Params::RelinearizationThreshold& relinearizeThreshold) const ISAM2Params::RelinearizationThreshold& relinearizeThreshold)
{ {
KeySet relinKeys; KeySet relinKeys;
BOOST_FOREACH(const ISAM2::sharedClique& root, roots) { for(const ISAM2::sharedClique& root: roots) {
if(relinearizeThreshold.type() == typeid(double)) if(relinearizeThreshold.type() == typeid(double))
CheckRelinearizationRecursiveDouble(relinKeys, boost::get<double>(relinearizeThreshold), delta, root); CheckRelinearizationRecursiveDouble(relinKeys, boost::get<double>(relinearizeThreshold), delta, root);
else if(relinearizeThreshold.type() == typeid(FastMap<char,Vector>)) else if(relinearizeThreshold.type() == typeid(FastMap<char,Vector>))
@ -207,7 +207,7 @@ void ISAM2::Impl::FindAll(ISAM2Clique::shared_ptr clique, KeySet& keys, const Ke
static const bool debug = false; static const bool debug = false;
// does the separator contain any of the variables? // does the separator contain any of the variables?
bool found = false; bool found = false;
BOOST_FOREACH(Key key, clique->conditional()->parents()) { for(Key key: clique->conditional()->parents()) {
if (markedMask.exists(key)) { if (markedMask.exists(key)) {
found = true; found = true;
break; break;
@ -219,7 +219,7 @@ void ISAM2::Impl::FindAll(ISAM2Clique::shared_ptr clique, KeySet& keys, const Ke
if(debug) clique->print("Key(s) marked in clique "); if(debug) clique->print("Key(s) marked in clique ");
if(debug) cout << "so marking key " << clique->conditional()->front() << endl; if(debug) cout << "so marking key " << clique->conditional()->front() << endl;
} }
BOOST_FOREACH(const ISAM2Clique::shared_ptr& child, clique->children) { for(const ISAM2Clique::shared_ptr& child: clique->children) {
FindAll(child, keys, markedMask); FindAll(child, keys, markedMask);
} }
} }
@ -267,7 +267,7 @@ inline static void optimizeInPlace(const boost::shared_ptr<ISAM2Clique>& clique,
result.update(clique->conditional()->solve(result)); result.update(clique->conditional()->solve(result));
// starting from the root, call optimize on each conditional // starting from the root, call optimize on each conditional
BOOST_FOREACH(const boost::shared_ptr<ISAM2Clique>& child, clique->children) for(const boost::shared_ptr<ISAM2Clique>& child: clique->children)
optimizeInPlace(child, result); optimizeInPlace(child, result);
} }
} }
@ -280,14 +280,14 @@ size_t ISAM2::Impl::UpdateGaussNewtonDelta(const FastVector<ISAM2::sharedClique>
if (wildfireThreshold <= 0.0) { if (wildfireThreshold <= 0.0) {
// Threshold is zero or less, so do a full recalculation // Threshold is zero or less, so do a full recalculation
BOOST_FOREACH(const ISAM2::sharedClique& root, roots) for(const ISAM2::sharedClique& root: roots)
internal::optimizeInPlace(root, delta); internal::optimizeInPlace(root, delta);
lastBacksubVariableCount = delta.size(); lastBacksubVariableCount = delta.size();
} else { } else {
// Optimize with wildfire // Optimize with wildfire
lastBacksubVariableCount = 0; lastBacksubVariableCount = 0;
BOOST_FOREACH(const ISAM2::sharedClique& root, roots) for(const ISAM2::sharedClique& root: roots)
lastBacksubVariableCount += optimizeWildfireNonRecursive( lastBacksubVariableCount += optimizeWildfireNonRecursive(
root, wildfireThreshold, replacedKeys, delta); // modifies delta root, wildfireThreshold, replacedKeys, delta); // modifies delta
@ -309,7 +309,7 @@ void updateRgProd(const boost::shared_ptr<ISAM2Clique>& clique, const KeySet& re
// update deltas and recurse to children, but if not, we do not need to // update deltas and recurse to children, but if not, we do not need to
// recurse further because of the running separator property. // recurse further because of the running separator property.
bool anyReplaced = false; bool anyReplaced = false;
BOOST_FOREACH(Key j, *clique->conditional()) { for(Key j: *clique->conditional()) {
if(replacedKeys.exists(j)) { if(replacedKeys.exists(j)) {
anyReplaced = true; anyReplaced = true;
break; break;
@ -327,7 +327,7 @@ void updateRgProd(const boost::shared_ptr<ISAM2Clique>& clique, const KeySet& re
// Write into RgProd vector // Write into RgProd vector
DenseIndex vectorPosition = 0; DenseIndex vectorPosition = 0;
BOOST_FOREACH(Key frontal, clique->conditional()->frontals()) { for(Key frontal: clique->conditional()->frontals()) {
Vector& RgProdValue = RgProd[frontal]; Vector& RgProdValue = RgProd[frontal];
RgProdValue = RSgProd.segment(vectorPosition, RgProdValue.size()); RgProdValue = RSgProd.segment(vectorPosition, RgProdValue.size());
vectorPosition += RgProdValue.size(); vectorPosition += RgProdValue.size();
@ -339,7 +339,7 @@ void updateRgProd(const boost::shared_ptr<ISAM2Clique>& clique, const KeySet& re
varsUpdated += clique->conditional()->nrFrontals(); varsUpdated += clique->conditional()->nrFrontals();
// Recurse to children // Recurse to children
BOOST_FOREACH(const ISAM2Clique::shared_ptr& child, clique->children) { for(const ISAM2Clique::shared_ptr& child: clique->children) {
updateRgProd(child, replacedKeys, grad, RgProd, varsUpdated); } updateRgProd(child, replacedKeys, grad, RgProd, varsUpdated); }
} }
} }
@ -351,7 +351,7 @@ size_t ISAM2::Impl::UpdateRgProd(const ISAM2::Roots& roots, const KeySet& replac
// Update variables // Update variables
size_t varsUpdated = 0; size_t varsUpdated = 0;
BOOST_FOREACH(const ISAM2::sharedClique& root, roots) { for(const ISAM2::sharedClique& root: roots) {
internal::updateRgProd(root, replacedKeys, gradAtZero, RgProd, varsUpdated); internal::updateRgProd(root, replacedKeys, gradAtZero, RgProd, varsUpdated);
} }

View File

@ -45,7 +45,7 @@ void optimizeWildfire(const boost::shared_ptr<CLIQUE>& clique, double threshold,
// Are any clique variables part of the tree that has been redone? // Are any clique variables part of the tree that has been redone?
bool cliqueReplaced = replaced.exists((*clique)->frontals().front()); bool cliqueReplaced = replaced.exists((*clique)->frontals().front());
#ifdef GTSAM_EXTRA_CONSISTENCY_CHECKS #ifdef GTSAM_EXTRA_CONSISTENCY_CHECKS
BOOST_FOREACH(Key frontal, clique->conditional()->frontals()) { for(Key frontal: clique->conditional()->frontals()) {
assert(cliqueReplaced == replaced.exists(frontal)); assert(cliqueReplaced == replaced.exists(frontal));
} }
#endif #endif
@ -53,7 +53,7 @@ void optimizeWildfire(const boost::shared_ptr<CLIQUE>& clique, double threshold,
// If not redone, then has one of the separator variables changed significantly? // If not redone, then has one of the separator variables changed significantly?
bool recalculate = cliqueReplaced; bool recalculate = cliqueReplaced;
if(!recalculate) { if(!recalculate) {
BOOST_FOREACH(Key parent, clique->conditional()->parents()) { for(Key parent: clique->conditional()->parents()) {
if(changed.exists(parent)) { if(changed.exists(parent)) {
recalculate = true; recalculate = true;
break; break;
@ -94,7 +94,7 @@ void optimizeWildfire(const boost::shared_ptr<CLIQUE>& clique, double threshold,
// If the values were above the threshold or this clique was replaced // If the values were above the threshold or this clique was replaced
if(valuesChanged) { if(valuesChanged) {
// Set changed flag for each frontal variable and leave the new values // Set changed flag for each frontal variable and leave the new values
BOOST_FOREACH(Key frontal, clique->conditional()->frontals()) { for(Key frontal: clique->conditional()->frontals()) {
changed.insert(frontal); changed.insert(frontal);
} }
} else { } else {
@ -105,7 +105,7 @@ void optimizeWildfire(const boost::shared_ptr<CLIQUE>& clique, double threshold,
} }
// Recurse to children // Recurse to children
BOOST_FOREACH(const typename CLIQUE::shared_ptr& child, clique->children) { for(const typename CLIQUE::shared_ptr& child: clique->children) {
optimizeWildfire(child, threshold, changed, replaced, delta, count); optimizeWildfire(child, threshold, changed, replaced, delta, count);
} }
} }
@ -122,7 +122,7 @@ bool optimizeWildfireNode(const boost::shared_ptr<CLIQUE>& clique, double thresh
// Are any clique variables part of the tree that has been redone? // Are any clique variables part of the tree that has been redone?
bool cliqueReplaced = replaced.exists(clique->conditional()->frontals().front()); bool cliqueReplaced = replaced.exists(clique->conditional()->frontals().front());
#ifdef GTSAM_EXTRA_CONSISTENCY_CHECKS #ifdef GTSAM_EXTRA_CONSISTENCY_CHECKS
BOOST_FOREACH(Key frontal, clique->conditional()->frontals()) { for(Key frontal: clique->conditional()->frontals()) {
assert(cliqueReplaced == replaced.exists(frontal)); assert(cliqueReplaced == replaced.exists(frontal));
} }
#endif #endif
@ -130,7 +130,7 @@ bool optimizeWildfireNode(const boost::shared_ptr<CLIQUE>& clique, double thresh
// If not redone, then has one of the separator variables changed significantly? // If not redone, then has one of the separator variables changed significantly?
bool recalculate = cliqueReplaced; bool recalculate = cliqueReplaced;
if(!recalculate) { if(!recalculate) {
BOOST_FOREACH(Key parent, clique->conditional()->parents()) { for(Key parent: clique->conditional()->parents()) {
if(changed.exists(parent)) { if(changed.exists(parent)) {
recalculate = true; recalculate = true;
break; break;
@ -156,9 +156,9 @@ bool optimizeWildfireNode(const boost::shared_ptr<CLIQUE>& clique, double thresh
boost::shared_ptr<CLIQUE> parent = clique->parent_.lock(); boost::shared_ptr<CLIQUE> parent = clique->parent_.lock();
if(clique->solnPointers_.empty() && (clique->isRoot() || !parent->solnPointers_.empty())) if(clique->solnPointers_.empty() && (clique->isRoot() || !parent->solnPointers_.empty()))
{ {
BOOST_FOREACH(Key key, clique->conditional()->frontals()) for(Key key: clique->conditional()->frontals())
clique->solnPointers_.insert(std::make_pair(key, delta.find(key))); clique->solnPointers_.insert(std::make_pair(key, delta.find(key)));
BOOST_FOREACH(Key key, clique->conditional()->parents()) for(Key key: clique->conditional()->parents())
clique->solnPointers_.insert(std::make_pair(key, parent->solnPointers_.at(key))); clique->solnPointers_.insert(std::make_pair(key, parent->solnPointers_.at(key)));
} }
@ -174,7 +174,7 @@ bool optimizeWildfireNode(const boost::shared_ptr<CLIQUE>& clique, double thresh
DenseIndex dim = 0; DenseIndex dim = 0;
FastVector<VectorValues::const_iterator> parentPointers; FastVector<VectorValues::const_iterator> parentPointers;
parentPointers.reserve(clique->conditional()->nrParents()); parentPointers.reserve(clique->conditional()->nrParents());
BOOST_FOREACH(Key parent, clique->conditional()->parents()) { for(Key parent: clique->conditional()->parents()) {
parentPointers.push_back(clique->solnPointers_.at(parent)); parentPointers.push_back(clique->solnPointers_.at(parent));
dim += parentPointers.back()->second.size(); dim += parentPointers.back()->second.size();
} }
@ -182,7 +182,7 @@ bool optimizeWildfireNode(const boost::shared_ptr<CLIQUE>& clique, double thresh
// Fill parent vector // Fill parent vector
xS.resize(dim); xS.resize(dim);
DenseIndex vectorPos = 0; DenseIndex vectorPos = 0;
BOOST_FOREACH(const VectorValues::const_iterator& parentPointer, parentPointers) { for(const VectorValues::const_iterator& parentPointer: parentPointers) {
const Vector& parentVector = parentPointer->second; const Vector& parentVector = parentPointer->second;
xS.block(vectorPos,0,parentVector.size(),1) = parentVector.block(0,0,parentVector.size(),1); xS.block(vectorPos,0,parentVector.size(),1) = parentVector.block(0,0,parentVector.size(),1);
vectorPos += parentVector.size(); vectorPos += parentVector.size();
@ -227,7 +227,7 @@ bool optimizeWildfireNode(const boost::shared_ptr<CLIQUE>& clique, double thresh
// If the values were above the threshold or this clique was replaced // If the values were above the threshold or this clique was replaced
if(valuesChanged) { if(valuesChanged) {
// Set changed flag for each frontal variable and leave the new values // Set changed flag for each frontal variable and leave the new values
BOOST_FOREACH(Key frontal, clique->conditional()->frontals()) { for(Key frontal: clique->conditional()->frontals()) {
changed.insert(frontal); changed.insert(frontal);
} }
} else { } else {
@ -270,7 +270,7 @@ size_t optimizeWildfireNonRecursive(const boost::shared_ptr<CLIQUE>& root, doubl
travStack.pop(); travStack.pop();
bool recalculate = internal::optimizeWildfireNode(currentNode, threshold, changed, keys, delta, count); bool recalculate = internal::optimizeWildfireNode(currentNode, threshold, changed, keys, delta, count);
if (recalculate) { if (recalculate) {
BOOST_FOREACH(const typename CLIQUE::shared_ptr& child, currentNode->children) { for(const typename CLIQUE::shared_ptr& child: currentNode->children) {
travStack.push(child); travStack.push(child);
} }
} }
@ -287,7 +287,7 @@ void nnz_internal(const boost::shared_ptr<CLIQUE>& clique, int& result) {
int dimSep = (int)clique->conditional()->get_S().cols(); int dimSep = (int)clique->conditional()->get_S().cols();
result += ((dimR+1)*dimR)/2 + dimSep*dimR; result += ((dimR+1)*dimR)/2 + dimSep*dimR;
// traverse the children // traverse the children
BOOST_FOREACH(const typename CLIQUE::shared_ptr& child, clique->children) { for(const typename CLIQUE::shared_ptr& child: clique->children) {
nnz_internal(child, result); nnz_internal(child, result);
} }
} }

View File

@ -15,7 +15,6 @@
* @author Michael Kaess, Richard Roberts * @author Michael Kaess, Richard Roberts
*/ */
#include <boost/foreach.hpp>
#include <boost/assign/std/list.hpp> // for operator += #include <boost/assign/std/list.hpp> // for operator +=
using namespace boost::assign; using namespace boost::assign;
#include <boost/range/adaptors.hpp> #include <boost/range/adaptors.hpp>
@ -174,17 +173,17 @@ bool ISAM2::equals(const ISAM2& other, double tol) const {
KeySet ISAM2::getAffectedFactors(const KeyList& keys) const { KeySet ISAM2::getAffectedFactors(const KeyList& keys) const {
static const bool debug = false; static const bool debug = false;
if(debug) cout << "Getting affected factors for "; if(debug) cout << "Getting affected factors for ";
if(debug) { BOOST_FOREACH(const Key key, keys) { cout << key << " "; } } if(debug) { for(const Key key: keys) { cout << key << " "; } }
if(debug) cout << endl; if(debug) cout << endl;
NonlinearFactorGraph allAffected; NonlinearFactorGraph allAffected;
KeySet indices; KeySet indices;
BOOST_FOREACH(const Key key, keys) { for(const Key key: keys) {
const VariableIndex::Factors& factors(variableIndex_[key]); const VariableIndex::Factors& factors(variableIndex_[key]);
indices.insert(factors.begin(), factors.end()); indices.insert(factors.begin(), factors.end());
} }
if(debug) cout << "Affected factors are: "; if(debug) cout << "Affected factors are: ";
if(debug) { BOOST_FOREACH(const size_t index, indices) { cout << index << " "; } } if(debug) { for(const size_t index: indices) { cout << index << " "; } }
if(debug) cout << endl; if(debug) cout << endl;
return indices; return indices;
} }
@ -210,10 +209,10 @@ ISAM2::relinearizeAffectedFactors(const FastList<Key>& affectedKeys, const KeySe
gttic(check_candidates_and_linearize); gttic(check_candidates_and_linearize);
GaussianFactorGraph::shared_ptr linearized = boost::make_shared<GaussianFactorGraph>(); GaussianFactorGraph::shared_ptr linearized = boost::make_shared<GaussianFactorGraph>();
BOOST_FOREACH(Key idx, candidates) { for(Key idx: candidates) {
bool inside = true; bool inside = true;
bool useCachedLinear = params_.cacheLinearizedFactors; bool useCachedLinear = params_.cacheLinearizedFactors;
BOOST_FOREACH(Key key, nonlinearFactors_[idx]->keys()) { for(Key key: nonlinearFactors_[idx]->keys()) {
if(affectedKeysSet.find(key) == affectedKeysSet.end()) { if(affectedKeysSet.find(key) == affectedKeysSet.end()) {
inside = false; inside = false;
break; break;
@ -251,7 +250,7 @@ ISAM2::relinearizeAffectedFactors(const FastList<Key>& affectedKeys, const KeySe
GaussianFactorGraph ISAM2::getCachedBoundaryFactors(Cliques& orphans) { GaussianFactorGraph ISAM2::getCachedBoundaryFactors(Cliques& orphans) {
GaussianFactorGraph cachedBoundary; GaussianFactorGraph cachedBoundary;
BOOST_FOREACH(sharedClique orphan, orphans) { for(sharedClique orphan: orphans) {
// retrieve the cached factor and add to boundary // retrieve the cached factor and add to boundary
cachedBoundary.push_back(orphan->cachedFactor()); cachedBoundary.push_back(orphan->cachedFactor());
} }
@ -292,10 +291,10 @@ boost::shared_ptr<KeySet > ISAM2::recalculate(const KeySet& markedKeys, const Ke
if(debug) { if(debug) {
cout << "markedKeys: "; cout << "markedKeys: ";
BOOST_FOREACH(const Key key, markedKeys) { cout << key << " "; } for(const Key key: markedKeys) { cout << key << " "; }
cout << endl; cout << endl;
cout << "observedKeys: "; cout << "observedKeys: ";
BOOST_FOREACH(const Key key, observedKeys) { cout << key << " "; } for(const Key key: observedKeys) { cout << key << " "; }
cout << endl; cout << endl;
} }
@ -322,7 +321,7 @@ boost::shared_ptr<KeySet > ISAM2::recalculate(const KeySet& markedKeys, const Ke
// ordering provides all keys in conditionals, there cannot be others because path to root included // ordering provides all keys in conditionals, there cannot be others because path to root included
gttic(affectedKeys); gttic(affectedKeys);
FastList<Key> affectedKeys; FastList<Key> affectedKeys;
BOOST_FOREACH(const ConditionalType::shared_ptr& conditional, affectedBayesNet) for(const ConditionalType::shared_ptr& conditional: affectedBayesNet)
affectedKeys.insert(affectedKeys.end(), conditional->beginFrontals(), conditional->endFrontals()); affectedKeys.insert(affectedKeys.end(), conditional->beginFrontals(), conditional->endFrontals());
gttoc(affectedKeys); gttoc(affectedKeys);
@ -349,7 +348,7 @@ boost::shared_ptr<KeySet > ISAM2::recalculate(const KeySet& markedKeys, const Ke
{ {
// Only if some variables are unconstrained // Only if some variables are unconstrained
FastMap<Key, int> constraintGroups; FastMap<Key, int> constraintGroups;
BOOST_FOREACH(Key var, observedKeys) for(Key var: observedKeys)
constraintGroups[var] = 1; constraintGroups[var] = 1;
order = Ordering::ColamdConstrained(variableIndex_, constraintGroups); order = Ordering::ColamdConstrained(variableIndex_, constraintGroups);
} }
@ -386,7 +385,7 @@ boost::shared_ptr<KeySet > ISAM2::recalculate(const KeySet& markedKeys, const Ke
// Reeliminated keys for detailed results // Reeliminated keys for detailed results
if(params_.enableDetailedResults) { if(params_.enableDetailedResults) {
BOOST_FOREACH(Key key, theta_.keys()) { for(Key key: theta_.keys()) {
result.detail->variableStatus[key].isReeliminated = true; result.detail->variableStatus[key].isReeliminated = true;
} }
} }
@ -406,11 +405,11 @@ boost::shared_ptr<KeySet > ISAM2::recalculate(const KeySet& markedKeys, const Ke
if(debug) factors.print("Relinearized factors: "); if(debug) factors.print("Relinearized factors: ");
gttoc(relinearizeAffected); gttoc(relinearizeAffected);
if(debug) { cout << "Affected keys: "; BOOST_FOREACH(const Key key, affectedKeys) { cout << key << " "; } cout << endl; } if(debug) { cout << "Affected keys: "; for(const Key key: affectedKeys) { cout << key << " "; } cout << endl; }
// Reeliminated keys for detailed results // Reeliminated keys for detailed results
if(params_.enableDetailedResults) { if(params_.enableDetailedResults) {
BOOST_FOREACH(Key key, affectedAndNewKeys) { for(Key key: affectedAndNewKeys) {
result.detail->variableStatus[key].isReeliminated = true; result.detail->variableStatus[key].isReeliminated = true;
} }
} }
@ -437,7 +436,7 @@ boost::shared_ptr<KeySet > ISAM2::recalculate(const KeySet& markedKeys, const Ke
gttic(orphans); gttic(orphans);
// Add the orphaned subtrees // Add the orphaned subtrees
BOOST_FOREACH(const sharedClique& orphan, orphans) for(const sharedClique& orphan: orphans)
factors += boost::make_shared<BayesTreeOrphanWrapper<Clique> >(orphan); factors += boost::make_shared<BayesTreeOrphanWrapper<Clique> >(orphan);
gttoc(orphans); gttoc(orphans);
@ -465,7 +464,7 @@ boost::shared_ptr<KeySet > ISAM2::recalculate(const KeySet& markedKeys, const Ke
} else { } else {
constraintGroups = FastMap<Key,int>(); constraintGroups = FastMap<Key,int>();
const int group = observedKeys.size() < affectedFactorsVarIndex.size() ? 1 : 0; const int group = observedKeys.size() < affectedFactorsVarIndex.size() ? 1 : 0;
BOOST_FOREACH (Key var, observedKeys) for (Key var: observedKeys)
constraintGroups.insert(make_pair(var, group)); constraintGroups.insert(make_pair(var, group));
} }
@ -500,8 +499,8 @@ boost::shared_ptr<KeySet > ISAM2::recalculate(const KeySet& markedKeys, const Ke
// Root clique variables for detailed results // Root clique variables for detailed results
if(params_.enableDetailedResults) { if(params_.enableDetailedResults) {
BOOST_FOREACH(const sharedNode& root, this->roots()) for(const sharedNode& root: this->roots())
BOOST_FOREACH(Key var, *root->conditional()) for(Key var: *root->conditional())
result.detail->variableStatus[var].inRootClique = true; result.detail->variableStatus[var].inRootClique = true;
} }
@ -554,7 +553,7 @@ ISAM2Result ISAM2::update(
// Remove the removed factors // Remove the removed factors
NonlinearFactorGraph removeFactors; removeFactors.reserve(removeFactorIndices.size()); NonlinearFactorGraph removeFactors; removeFactors.reserve(removeFactorIndices.size());
BOOST_FOREACH(size_t index, removeFactorIndices) { for(size_t index: removeFactorIndices) {
removeFactors.push_back(nonlinearFactors_[index]); removeFactors.push_back(nonlinearFactors_[index]);
nonlinearFactors_.remove(index); nonlinearFactors_.remove(index);
if(params_.cacheLinearizedFactors) if(params_.cacheLinearizedFactors)
@ -571,7 +570,7 @@ ISAM2Result ISAM2::update(
// Get keys from removed factors and new factors, and compute unused keys, // Get keys from removed factors and new factors, and compute unused keys,
// i.e., keys that are empty now and do not appear in the new factors. // i.e., keys that are empty now and do not appear in the new factors.
KeySet removedAndEmpty; KeySet removedAndEmpty;
BOOST_FOREACH(Key key, removeFactors.keys()) { for(Key key: removeFactors.keys()) {
if(variableIndex_[key].empty()) if(variableIndex_[key].empty())
removedAndEmpty.insert(removedAndEmpty.end(), key); removedAndEmpty.insert(removedAndEmpty.end(), key);
} }
@ -580,7 +579,7 @@ ISAM2Result ISAM2::update(
newFactorSymbKeys.begin(), newFactorSymbKeys.end(), std::inserter(unusedKeys, unusedKeys.end())); newFactorSymbKeys.begin(), newFactorSymbKeys.end(), std::inserter(unusedKeys, unusedKeys.end()));
// Get indices for unused keys // Get indices for unused keys
BOOST_FOREACH(Key key, unusedKeys) { for(Key key: unusedKeys) {
unusedIndices.insert(unusedIndices.end(), key); unusedIndices.insert(unusedIndices.end(), key);
} }
} }
@ -591,7 +590,7 @@ ISAM2Result ISAM2::update(
Impl::AddVariables(newTheta, theta_, delta_, deltaNewton_, RgProd_); Impl::AddVariables(newTheta, theta_, delta_, deltaNewton_, RgProd_);
// New keys for detailed results // New keys for detailed results
if(params_.enableDetailedResults) { if(params_.enableDetailedResults) {
BOOST_FOREACH(Key key, newTheta.keys()) { result.detail->variableStatus[key].isNew = true; } } for(Key key: newTheta.keys()) { result.detail->variableStatus[key].isNew = true; } }
gttoc(add_new_variables); gttoc(add_new_variables);
gttic(evaluate_error_before); gttic(evaluate_error_before);
@ -609,14 +608,14 @@ ISAM2Result ISAM2::update(
} }
// Also mark any provided extra re-eliminate keys // Also mark any provided extra re-eliminate keys
if(extraReelimKeys) { if(extraReelimKeys) {
BOOST_FOREACH(Key key, *extraReelimKeys) { for(Key key: *extraReelimKeys) {
markedKeys.insert(key); markedKeys.insert(key);
} }
} }
// Observed keys for detailed results // Observed keys for detailed results
if(params_.enableDetailedResults) { if(params_.enableDetailedResults) {
BOOST_FOREACH(Key key, markedKeys) { for(Key key: markedKeys) {
result.detail->variableStatus[key].isObserved = true; result.detail->variableStatus[key].isObserved = true;
} }
} }
@ -624,7 +623,7 @@ ISAM2Result ISAM2::update(
// is a vector of size_t, so the constructor unintentionally resolves to // is a vector of size_t, so the constructor unintentionally resolves to
// vector(size_t count, Key value) instead of the iterator constructor. // vector(size_t count, Key value) instead of the iterator constructor.
FastVector<Key> observedKeys; observedKeys.reserve(markedKeys.size()); FastVector<Key> observedKeys; observedKeys.reserve(markedKeys.size());
BOOST_FOREACH(Key index, markedKeys) { for(Key index: markedKeys) {
if(unusedIndices.find(index) == unusedIndices.end()) // Only add if not unused if(unusedIndices.find(index) == unusedIndices.end()) // Only add if not unused
observedKeys.push_back(index); // Make a copy of these, as we'll soon add to them observedKeys.push_back(index); // Make a copy of these, as we'll soon add to them
} }
@ -642,24 +641,24 @@ ISAM2Result ISAM2::update(
if(disableReordering) relinKeys = Impl::CheckRelinearizationFull(delta_, 0.0); // This is used for debugging if(disableReordering) relinKeys = Impl::CheckRelinearizationFull(delta_, 0.0); // This is used for debugging
// Remove from relinKeys any keys whose linearization points are fixed // Remove from relinKeys any keys whose linearization points are fixed
BOOST_FOREACH(Key key, fixedVariables_) { for(Key key: fixedVariables_) {
relinKeys.erase(key); relinKeys.erase(key);
} }
if(noRelinKeys) { if(noRelinKeys) {
BOOST_FOREACH(Key key, *noRelinKeys) { for(Key key: *noRelinKeys) {
relinKeys.erase(key); relinKeys.erase(key);
} }
} }
// Above relin threshold keys for detailed results // Above relin threshold keys for detailed results
if(params_.enableDetailedResults) { if(params_.enableDetailedResults) {
BOOST_FOREACH(Key key, relinKeys) { for(Key key: relinKeys) {
result.detail->variableStatus[key].isAboveRelinThreshold = true; result.detail->variableStatus[key].isAboveRelinThreshold = true;
result.detail->variableStatus[key].isRelinearized = true; } } result.detail->variableStatus[key].isRelinearized = true; } }
// Add the variables being relinearized to the marked keys // Add the variables being relinearized to the marked keys
KeySet markedRelinMask; KeySet markedRelinMask;
BOOST_FOREACH(const Key key, relinKeys) for(const Key key: relinKeys)
markedRelinMask.insert(key); markedRelinMask.insert(key);
markedKeys.insert(relinKeys.begin(), relinKeys.end()); markedKeys.insert(relinKeys.begin(), relinKeys.end());
gttoc(gather_relinearize_keys); gttoc(gather_relinearize_keys);
@ -667,16 +666,16 @@ ISAM2Result ISAM2::update(
gttic(fluid_find_all); gttic(fluid_find_all);
// 5. Mark all cliques that involve marked variables \Theta_{J} and all their ancestors. // 5. Mark all cliques that involve marked variables \Theta_{J} and all their ancestors.
if (!relinKeys.empty()) { if (!relinKeys.empty()) {
BOOST_FOREACH(const sharedClique& root, roots_) for(const sharedClique& root: roots_)
// add other cliques that have the marked ones in the separator // add other cliques that have the marked ones in the separator
Impl::FindAll(root, markedKeys, markedRelinMask); Impl::FindAll(root, markedKeys, markedRelinMask);
// Relin involved keys for detailed results // Relin involved keys for detailed results
if(params_.enableDetailedResults) { if(params_.enableDetailedResults) {
KeySet involvedRelinKeys; KeySet involvedRelinKeys;
BOOST_FOREACH(const sharedClique& root, roots_) for(const sharedClique& root: roots_)
Impl::FindAll(root, involvedRelinKeys, markedRelinMask); Impl::FindAll(root, involvedRelinKeys, markedRelinMask);
BOOST_FOREACH(Key key, involvedRelinKeys) { for(Key key: involvedRelinKeys) {
if(!result.detail->variableStatus[key].isAboveRelinThreshold) { if(!result.detail->variableStatus[key].isAboveRelinThreshold) {
result.detail->variableStatus[key].isRelinearizeInvolved = true; result.detail->variableStatus[key].isRelinearizeInvolved = true;
result.detail->variableStatus[key].isRelinearized = true; } } result.detail->variableStatus[key].isRelinearized = true; } }
@ -771,7 +770,7 @@ void ISAM2::marginalizeLeaves(const FastList<Key>& leafKeysList,
KeySet leafKeysRemoved; KeySet leafKeysRemoved;
// Remove each variable and its subtrees // Remove each variable and its subtrees
BOOST_FOREACH(Key j, leafKeys) { for(Key j: leafKeys) {
if(!leafKeysRemoved.exists(j)) { // If the index was not already removed by removing another subtree if(!leafKeysRemoved.exists(j)) { // If the index was not already removed by removing another subtree
// Traverse up the tree to find the root of the marginalized subtree // Traverse up the tree to find the root of the marginalized subtree
@ -789,7 +788,7 @@ void ISAM2::marginalizeLeaves(const FastList<Key>& leafKeysList,
// See if we should remove the whole clique // See if we should remove the whole clique
bool marginalizeEntireClique = true; bool marginalizeEntireClique = true;
BOOST_FOREACH(Key frontal, clique->conditional()->frontals()) { for(Key frontal: clique->conditional()->frontals()) {
if(!leafKeys.exists(frontal)) { if(!leafKeys.exists(frontal)) {
marginalizeEntireClique = false; marginalizeEntireClique = false;
break; } } break; } }
@ -806,10 +805,10 @@ void ISAM2::marginalizeLeaves(const FastList<Key>& leafKeysList,
// Now remove this clique and its subtree - all of its marginal // Now remove this clique and its subtree - all of its marginal
// information has been stored in marginalFactors. // information has been stored in marginalFactors.
const Cliques removedCliques = this->removeSubtree(clique); // Remove the subtree and throw away the cliques const Cliques removedCliques = this->removeSubtree(clique); // Remove the subtree and throw away the cliques
BOOST_FOREACH(const sharedClique& removedClique, removedCliques) { for(const sharedClique& removedClique: removedCliques) {
marginalFactors.erase(removedClique->conditional()->front()); marginalFactors.erase(removedClique->conditional()->front());
leafKeysRemoved.insert(removedClique->conditional()->beginFrontals(), removedClique->conditional()->endFrontals()); leafKeysRemoved.insert(removedClique->conditional()->beginFrontals(), removedClique->conditional()->endFrontals());
BOOST_FOREACH(Key frontal, removedClique->conditional()->frontals()) for(Key frontal: removedClique->conditional()->frontals())
{ {
// Add to factors to remove // Add to factors to remove
const VariableIndex::Factors& involvedFactors = variableIndex_[frontal]; const VariableIndex::Factors& involvedFactors = variableIndex_[frontal];
@ -832,9 +831,9 @@ void ISAM2::marginalizeLeaves(const FastList<Key>& leafKeysList,
GaussianFactorGraph graph; GaussianFactorGraph graph;
KeySet factorsInSubtreeRoot; KeySet factorsInSubtreeRoot;
Cliques subtreesToRemove; Cliques subtreesToRemove;
BOOST_FOREACH(const sharedClique& child, clique->children) { for(const sharedClique& child: clique->children) {
// Remove subtree if child depends on any marginalized keys // Remove subtree if child depends on any marginalized keys
BOOST_FOREACH(Key parent, child->conditional()->parents()) { for(Key parent: child->conditional()->parents()) {
if(leafKeys.exists(parent)) { if(leafKeys.exists(parent)) {
subtreesToRemove.push_back(child); subtreesToRemove.push_back(child);
graph.push_back(child->cachedFactor()); // Add child marginal graph.push_back(child->cachedFactor()); // Add child marginal
@ -843,13 +842,13 @@ void ISAM2::marginalizeLeaves(const FastList<Key>& leafKeysList,
} }
} }
Cliques childrenRemoved; Cliques childrenRemoved;
BOOST_FOREACH(const sharedClique& childToRemove, subtreesToRemove) { for(const sharedClique& childToRemove: subtreesToRemove) {
const Cliques removedCliques = this->removeSubtree(childToRemove); // Remove the subtree and throw away the cliques const Cliques removedCliques = this->removeSubtree(childToRemove); // Remove the subtree and throw away the cliques
childrenRemoved.insert(childrenRemoved.end(), removedCliques.begin(), removedCliques.end()); childrenRemoved.insert(childrenRemoved.end(), removedCliques.begin(), removedCliques.end());
BOOST_FOREACH(const sharedClique& removedClique, removedCliques) { for(const sharedClique& removedClique: removedCliques) {
marginalFactors.erase(removedClique->conditional()->front()); marginalFactors.erase(removedClique->conditional()->front());
leafKeysRemoved.insert(removedClique->conditional()->beginFrontals(), removedClique->conditional()->endFrontals()); leafKeysRemoved.insert(removedClique->conditional()->beginFrontals(), removedClique->conditional()->endFrontals());
BOOST_FOREACH(Key frontal, removedClique->conditional()->frontals()) for(Key frontal: removedClique->conditional()->frontals())
{ {
// Add to factors to remove // Add to factors to remove
const VariableIndex::Factors& involvedFactors = variableIndex_[frontal]; const VariableIndex::Factors& involvedFactors = variableIndex_[frontal];
@ -867,16 +866,16 @@ void ISAM2::marginalizeLeaves(const FastList<Key>& leafKeysList,
// but do not involve frontal variables of any of its children. // but do not involve frontal variables of any of its children.
// TODO: reuse cached linear factors // TODO: reuse cached linear factors
KeySet factorsFromMarginalizedInClique_step1; KeySet factorsFromMarginalizedInClique_step1;
BOOST_FOREACH(Key frontal, clique->conditional()->frontals()) { for(Key frontal: clique->conditional()->frontals()) {
if(leafKeys.exists(frontal)) if(leafKeys.exists(frontal))
factorsFromMarginalizedInClique_step1.insert(variableIndex_[frontal].begin(), variableIndex_[frontal].end()); } factorsFromMarginalizedInClique_step1.insert(variableIndex_[frontal].begin(), variableIndex_[frontal].end()); }
// Remove any factors in subtrees that we're removing at this step // Remove any factors in subtrees that we're removing at this step
BOOST_FOREACH(const sharedClique& removedChild, childrenRemoved) { for(const sharedClique& removedChild: childrenRemoved) {
BOOST_FOREACH(Key indexInClique, removedChild->conditional()->frontals()) { for(Key indexInClique: removedChild->conditional()->frontals()) {
BOOST_FOREACH(Key factorInvolving, variableIndex_[indexInClique]) { for(Key factorInvolving: variableIndex_[indexInClique]) {
factorsFromMarginalizedInClique_step1.erase(factorInvolving); } } } factorsFromMarginalizedInClique_step1.erase(factorInvolving); } } }
// Create factor graph from factor indices // Create factor graph from factor indices
BOOST_FOREACH(size_t i, factorsFromMarginalizedInClique_step1) { for(size_t i: factorsFromMarginalizedInClique_step1) {
graph.push_back(nonlinearFactors_[i]->linearize(theta_)); } graph.push_back(nonlinearFactors_[i]->linearize(theta_)); }
// Reeliminate the linear graph to get the marginal and discard the conditional // Reeliminate the linear graph to get the marginal and discard the conditional
@ -908,7 +907,7 @@ void ISAM2::marginalizeLeaves(const FastList<Key>& leafKeysList,
clique->conditional()->nrFrontals() -= nToRemove; clique->conditional()->nrFrontals() -= nToRemove;
// Add to factors to remove factors involved in frontals of current clique // Add to factors to remove factors involved in frontals of current clique
BOOST_FOREACH(Key frontal, cliqueFrontalsToEliminate) for(Key frontal: cliqueFrontalsToEliminate)
{ {
const VariableIndex::Factors& involvedFactors = variableIndex_[frontal]; const VariableIndex::Factors& involvedFactors = variableIndex_[frontal];
factorIndicesToRemove.insert(involvedFactors.begin(), involvedFactors.end()); factorIndicesToRemove.insert(involvedFactors.begin(), involvedFactors.end());
@ -925,8 +924,8 @@ void ISAM2::marginalizeLeaves(const FastList<Key>& leafKeysList,
// Gather factors to add - the new marginal factors // Gather factors to add - the new marginal factors
GaussianFactorGraph factorsToAdd; GaussianFactorGraph factorsToAdd;
typedef pair<Key, vector<GaussianFactor::shared_ptr> > Key_Factors; typedef pair<Key, vector<GaussianFactor::shared_ptr> > Key_Factors;
BOOST_FOREACH(const Key_Factors& key_factors, marginalFactors) { for(const Key_Factors& key_factors: marginalFactors) {
BOOST_FOREACH(const GaussianFactor::shared_ptr& factor, key_factors.second) { for(const GaussianFactor::shared_ptr& factor: key_factors.second) {
if(factor) { if(factor) {
factorsToAdd.push_back(factor); factorsToAdd.push_back(factor);
if(marginalFactorsIndices) if(marginalFactorsIndices)
@ -935,7 +934,7 @@ void ISAM2::marginalizeLeaves(const FastList<Key>& leafKeysList,
factor)); factor));
if(params_.cacheLinearizedFactors) if(params_.cacheLinearizedFactors)
linearFactors_.push_back(factor); linearFactors_.push_back(factor);
BOOST_FOREACH(Key factorKey, *factor) { for(Key factorKey: *factor) {
fixedVariables_.insert(factorKey); } fixedVariables_.insert(factorKey); }
} }
} }
@ -944,7 +943,7 @@ void ISAM2::marginalizeLeaves(const FastList<Key>& leafKeysList,
// Remove the factors to remove that have been summarized in the newly-added marginal factors // Remove the factors to remove that have been summarized in the newly-added marginal factors
NonlinearFactorGraph removedFactors; NonlinearFactorGraph removedFactors;
BOOST_FOREACH(size_t i, factorIndicesToRemove) { for(size_t i: factorIndicesToRemove) {
removedFactors.push_back(nonlinearFactors_[i]); removedFactors.push_back(nonlinearFactors_[i]);
nonlinearFactors_.remove(i); nonlinearFactors_.remove(i);
if(params_.cacheLinearizedFactors) if(params_.cacheLinearizedFactors)
@ -1065,7 +1064,7 @@ static void gradientAtZeroTreeAdder(const boost::shared_ptr<ISAM2Clique>& root,
// Recursively add contributions from children // Recursively add contributions from children
typedef boost::shared_ptr<ISAM2Clique> sharedClique; typedef boost::shared_ptr<ISAM2Clique> sharedClique;
BOOST_FOREACH(const sharedClique& child, root->children) { for(const sharedClique& child: root->children) {
gradientAtZeroTreeAdder(child, g); gradientAtZeroTreeAdder(child, g);
} }
} }
@ -1077,7 +1076,7 @@ VectorValues ISAM2::gradientAtZero() const
VectorValues g; VectorValues g;
// Sum up contributions for each clique // Sum up contributions for each clique
BOOST_FOREACH(const ISAM2::sharedClique& root, this->roots()) for(const ISAM2::sharedClique& root: this->roots())
gradientAtZeroTreeAdder(root, g); gradientAtZeroTreeAdder(root, g);
return g; return g;

View File

@ -200,7 +200,7 @@ struct GTSAM_EXPORT ISAM2Params {
else else
{ {
std::cout << "relinearizeThreshold: " << "{mapped}" << "\n"; std::cout << "relinearizeThreshold: " << "{mapped}" << "\n";
BOOST_FOREACH(const ISAM2ThresholdMapValue& value, boost::get<ISAM2ThresholdMap>(relinearizeThreshold)) { for(const ISAM2ThresholdMapValue& value: boost::get<ISAM2ThresholdMap>(relinearizeThreshold)) {
std::cout << " '" << value.first << "' -> [" << value.second.transpose() << " ]\n"; std::cout << " '" << value.first << "' -> [" << value.second.transpose() << " ]\n";
} }
} }

View File

@ -157,7 +157,7 @@ GaussianFactorGraph::shared_ptr LevenbergMarquardtOptimizer::buildDampedSystem(
// Only retrieve diagonal vector when reuse_diagonal = false // Only retrieve diagonal vector when reuse_diagonal = false
if (params_.diagonalDamping && state_.reuseDiagonal == false) { if (params_.diagonalDamping && state_.reuseDiagonal == false) {
state_.hessianDiagonal = linear.hessianDiagonal(); state_.hessianDiagonal = linear.hessianDiagonal();
BOOST_FOREACH(Vector& v, state_.hessianDiagonal | map_values) { for(Vector& v: state_.hessianDiagonal | map_values) {
for (int aa = 0; aa < v.size(); aa++) { for (int aa = 0; aa < v.size(); aa++) {
v(aa) = std::min(std::max(v(aa), params_.minDiagonal), v(aa) = std::min(std::max(v(aa), params_.minDiagonal),
params_.maxDiagonal); params_.maxDiagonal);
@ -172,7 +172,7 @@ GaussianFactorGraph::shared_ptr LevenbergMarquardtOptimizer::buildDampedSystem(
GaussianFactorGraph &damped = (*dampedPtr); GaussianFactorGraph &damped = (*dampedPtr);
damped.reserve(damped.size() + state_.values.size()); damped.reserve(damped.size() + state_.values.size());
if (params_.diagonalDamping) { if (params_.diagonalDamping) {
BOOST_FOREACH(const VectorValues::KeyValuePair& key_vector, state_.hessianDiagonal) { for(const VectorValues::KeyValuePair& key_vector: state_.hessianDiagonal) {
// Fill in the diagonal of A with diag(hessian) // Fill in the diagonal of A with diag(hessian)
try { try {
Matrix A = Eigen::DiagonalMatrix<double, Eigen::Dynamic>( Matrix A = Eigen::DiagonalMatrix<double, Eigen::Dynamic>(
@ -192,7 +192,7 @@ GaussianFactorGraph::shared_ptr LevenbergMarquardtOptimizer::buildDampedSystem(
// initialize noise model cache to a reasonable default size // initialize noise model cache to a reasonable default size
NoiseCacheVector noises(6); NoiseCacheVector noises(6);
BOOST_FOREACH(const Values::KeyValuePair& key_value, state_.values) { for(const Values::KeyValuePair& key_value: state_.values) {
size_t dim = key_value.value.dim(); size_t dim = key_value.value.dim();
if (dim > noises.size()) if (dim > noises.size())

View File

@ -11,7 +11,6 @@
#include <gtsam/linear/VectorValues.h> #include <gtsam/linear/VectorValues.h>
#include <gtsam/linear/GaussianFactorGraph.h> #include <gtsam/linear/GaussianFactorGraph.h>
#include <boost/foreach.hpp>
namespace gtsam { namespace gtsam {
@ -19,7 +18,7 @@ namespace gtsam {
void LinearContainerFactor::initializeLinearizationPoint(const Values& linearizationPoint) { void LinearContainerFactor::initializeLinearizationPoint(const Values& linearizationPoint) {
if (!linearizationPoint.empty()) { if (!linearizationPoint.empty()) {
linearizationPoint_ = Values(); linearizationPoint_ = Values();
BOOST_FOREACH(const gtsam::Key& key, this->keys()) { for(const gtsam::Key& key: this->keys()) {
linearizationPoint_->insert(key, linearizationPoint.at(key)); linearizationPoint_->insert(key, linearizationPoint.at(key));
} }
} else { } else {
@ -82,7 +81,7 @@ double LinearContainerFactor::error(const Values& c) const {
// Extract subset of values for comparison // Extract subset of values for comparison
Values csub; Values csub;
BOOST_FOREACH(const gtsam::Key& key, keys()) for(const gtsam::Key& key: keys())
csub.insert(key, c.at(key)); csub.insert(key, c.at(key));
// create dummy ordering for evaluation // create dummy ordering for evaluation
@ -111,7 +110,7 @@ GaussianFactor::shared_ptr LinearContainerFactor::linearize(const Values& c) con
// Extract subset of values // Extract subset of values
Values subsetC; Values subsetC;
BOOST_FOREACH(const gtsam::Key& key, this->keys()) for(const gtsam::Key& key: this->keys())
subsetC.insert(key, c.at(key)); subsetC.insert(key, c.at(key));
// Determine delta between linearization points using new ordering // Determine delta between linearization points using new ordering
@ -170,7 +169,7 @@ NonlinearFactorGraph LinearContainerFactor::convertLinearGraph(
const GaussianFactorGraph& linear_graph, const Values& linearizationPoint) const GaussianFactorGraph& linear_graph, const Values& linearizationPoint)
{ {
NonlinearFactorGraph result; NonlinearFactorGraph result;
BOOST_FOREACH(const GaussianFactor::shared_ptr& f, linear_graph) for(const GaussianFactor::shared_ptr& f: linear_graph)
if (f) if (f)
result.push_back(NonlinearFactorGraph::sharedFactor( result.push_back(NonlinearFactorGraph::sharedFactor(
new LinearContainerFactor(f, linearizationPoint))); new LinearContainerFactor(f, linearizationPoint)));

View File

@ -127,7 +127,7 @@ JointMarginal Marginals::jointMarginalInformation(const std::vector<Key>& variab
// Get dimensions from factor graph // Get dimensions from factor graph
std::vector<size_t> dims; std::vector<size_t> dims;
dims.reserve(variablesSorted.size()); dims.reserve(variablesSorted.size());
BOOST_FOREACH(Key key, variablesSorted) { for(Key key: variablesSorted) {
dims.push_back(values_.at(key).dim()); dims.push_back(values_.at(key).dim());
} }
@ -144,7 +144,7 @@ VectorValues Marginals::optimize() const {
void JointMarginal::print(const std::string& s, const KeyFormatter& formatter) const { void JointMarginal::print(const std::string& s, const KeyFormatter& formatter) const {
cout << s << "Joint marginal on keys "; cout << s << "Joint marginal on keys ";
bool first = true; bool first = true;
BOOST_FOREACH(Key key, keys_) { for(Key key: keys_) {
if(!first) if(!first)
cout << ", "; cout << ", ";
else else

View File

@ -26,7 +26,7 @@ namespace gtsam {
void NonlinearFactor::print(const std::string& s, void NonlinearFactor::print(const std::string& s,
const KeyFormatter& keyFormatter) const { const KeyFormatter& keyFormatter) const {
std::cout << s << " keys = { "; std::cout << s << " keys = { ";
BOOST_FOREACH(Key key, keys()) { for(Key key: keys()) {
std::cout << keyFormatter(key) << " "; std::cout << keyFormatter(key) << " ";
} }
std::cout << "}" << std::endl; std::cout << "}" << std::endl;

View File

@ -31,7 +31,6 @@
# include <tbb/parallel_for.h> # include <tbb/parallel_for.h>
#endif #endif
#include <boost/foreach.hpp>
#include <cmath> #include <cmath>
#include <limits> #include <limits>
@ -133,7 +132,7 @@ void NonlinearFactorGraph::saveGraph(std::ostream &stm, const Values& values,
// Find bounds // Find bounds
double minX = numeric_limits<double>::infinity(), maxX = -numeric_limits<double>::infinity(); double minX = numeric_limits<double>::infinity(), maxX = -numeric_limits<double>::infinity();
double minY = numeric_limits<double>::infinity(), maxY = -numeric_limits<double>::infinity(); double minY = numeric_limits<double>::infinity(), maxY = -numeric_limits<double>::infinity();
BOOST_FOREACH(Key key, keys) { for(Key key: keys) {
if(values.exists(key)) { if(values.exists(key)) {
boost::optional<Point2> xy = getXY(values.at(key), formatting); boost::optional<Point2> xy = getXY(values.at(key), formatting);
if(xy) { if(xy) {
@ -150,7 +149,7 @@ void NonlinearFactorGraph::saveGraph(std::ostream &stm, const Values& values,
} }
// Create nodes for each variable in the graph // Create nodes for each variable in the graph
BOOST_FOREACH(Key key, keys){ for(Key key: keys){
// Label the node with the label from the KeyFormatter // Label the node with the label from the KeyFormatter
stm << " var" << key << "[label=\"" << keyFormatter(key) << "\""; stm << " var" << key << "[label=\"" << keyFormatter(key) << "\"";
if(values.exists(key)) { if(values.exists(key)) {
@ -165,7 +164,7 @@ void NonlinearFactorGraph::saveGraph(std::ostream &stm, const Values& values,
if (formatting.mergeSimilarFactors) { if (formatting.mergeSimilarFactors) {
// Remove duplicate factors // Remove duplicate factors
std::set<vector<Key> > structure; std::set<vector<Key> > structure;
BOOST_FOREACH(const sharedFactor& factor, *this){ for(const sharedFactor& factor: *this){
if(factor) { if(factor) {
vector<Key> factorKeys = factor->keys(); vector<Key> factorKeys = factor->keys();
std::sort(factorKeys.begin(), factorKeys.end()); std::sort(factorKeys.begin(), factorKeys.end());
@ -175,7 +174,7 @@ void NonlinearFactorGraph::saveGraph(std::ostream &stm, const Values& values,
// Create factors and variable connections // Create factors and variable connections
size_t i = 0; size_t i = 0;
BOOST_FOREACH(const vector<Key>& factorKeys, structure){ for(const vector<Key>& factorKeys: structure){
// Make each factor a dot // Make each factor a dot
stm << " factor" << i << "[label=\"\", shape=point"; stm << " factor" << i << "[label=\"\", shape=point";
{ {
@ -187,7 +186,7 @@ void NonlinearFactorGraph::saveGraph(std::ostream &stm, const Values& values,
stm << "];\n"; stm << "];\n";
// Make factor-variable connections // Make factor-variable connections
BOOST_FOREACH(Key key, factorKeys) { for(Key key: factorKeys) {
stm << " var" << key << "--" << "factor" << i << ";\n"; stm << " var" << key << "--" << "factor" << i << ";\n";
} }
@ -214,7 +213,7 @@ void NonlinearFactorGraph::saveGraph(std::ostream &stm, const Values& values,
// Make factor-variable connections // Make factor-variable connections
if(formatting.connectKeysToFactor && factor) { if(formatting.connectKeysToFactor && factor) {
BOOST_FOREACH(Key key, *factor) { for(Key key: *factor) {
stm << " var" << key << "--" << "factor" << i << ";\n"; stm << " var" << key << "--" << "factor" << i << ";\n";
} }
} }
@ -224,7 +223,7 @@ void NonlinearFactorGraph::saveGraph(std::ostream &stm, const Values& values,
if(factor) { if(factor) {
Key k; Key k;
bool firstTime = true; bool firstTime = true;
BOOST_FOREACH(Key key, *this->at(i)) { for(Key key: *this->at(i)) {
if(firstTime) { if(firstTime) {
k = key; k = key;
firstTime = false; firstTime = false;
@ -246,7 +245,7 @@ double NonlinearFactorGraph::error(const Values& values) const {
gttic(NonlinearFactorGraph_error); gttic(NonlinearFactorGraph_error);
double total_error = 0.; double total_error = 0.;
// iterate over all the factors_ to accumulate the log probabilities // iterate over all the factors_ to accumulate the log probabilities
BOOST_FOREACH(const sharedFactor& factor, this->factors_) { for(const sharedFactor& factor: this->factors_) {
if(factor) if(factor)
total_error += factor->error(values); total_error += factor->error(values);
} }
@ -272,7 +271,7 @@ SymbolicFactorGraph::shared_ptr NonlinearFactorGraph::symbolic() const
SymbolicFactorGraph::shared_ptr symbolic = boost::make_shared<SymbolicFactorGraph>(); SymbolicFactorGraph::shared_ptr symbolic = boost::make_shared<SymbolicFactorGraph>();
symbolic->reserve(this->size()); symbolic->reserve(this->size());
BOOST_FOREACH(const sharedFactor& factor, *this) { for(const sharedFactor& factor: *this) {
if(factor) if(factor)
*symbolic += SymbolicFactor(*factor); *symbolic += SymbolicFactor(*factor);
else else
@ -330,7 +329,7 @@ GaussianFactorGraph::shared_ptr NonlinearFactorGraph::linearize(const Values& li
linearFG->reserve(this->size()); linearFG->reserve(this->size());
// linearize all factors // linearize all factors
BOOST_FOREACH(const sharedFactor& factor, this->factors_) { for(const sharedFactor& factor: this->factors_) {
if(factor) { if(factor) {
(*linearFG) += factor->linearize(linearizationPoint); (*linearFG) += factor->linearize(linearizationPoint);
} else } else
@ -345,7 +344,7 @@ GaussianFactorGraph::shared_ptr NonlinearFactorGraph::linearize(const Values& li
/* ************************************************************************* */ /* ************************************************************************* */
NonlinearFactorGraph NonlinearFactorGraph::clone() const { NonlinearFactorGraph NonlinearFactorGraph::clone() const {
NonlinearFactorGraph result; NonlinearFactorGraph result;
BOOST_FOREACH(const sharedFactor& f, *this) { for(const sharedFactor& f: *this) {
if (f) if (f)
result.push_back(f->clone()); result.push_back(f->clone());
else else
@ -357,7 +356,7 @@ NonlinearFactorGraph NonlinearFactorGraph::clone() const {
/* ************************************************************************* */ /* ************************************************************************* */
NonlinearFactorGraph NonlinearFactorGraph::rekey(const std::map<Key,Key>& rekey_mapping) const { NonlinearFactorGraph NonlinearFactorGraph::rekey(const std::map<Key,Key>& rekey_mapping) const {
NonlinearFactorGraph result; NonlinearFactorGraph result;
BOOST_FOREACH(const sharedFactor& f, *this) { for(const sharedFactor& f: *this) {
if (f) if (f)
result.push_back(f->rekey(rekey_mapping)); result.push_back(f->rekey(rekey_mapping));
else else

View File

@ -16,12 +16,9 @@
*/ */
#include <gtsam/nonlinear/NonlinearISAM.h> #include <gtsam/nonlinear/NonlinearISAM.h>
#include <gtsam/linear/GaussianFactorGraph.h> #include <gtsam/linear/GaussianFactorGraph.h>
#include <gtsam/inference/Ordering.h> #include <gtsam/inference/Ordering.h>
#include <boost/foreach.hpp>
#include <iostream> #include <iostream>
using namespace std; using namespace std;

View File

@ -26,8 +26,6 @@
#include <utility> #include <utility>
#include <boost/foreach.hpp>
#include <gtsam/base/DerivedValue.h> #include <gtsam/base/DerivedValue.h>
#include <gtsam/nonlinear/Values.h> // Only so Eclipse finds class definition #include <gtsam/nonlinear/Values.h> // Only so Eclipse finds class definition
@ -220,7 +218,7 @@ namespace gtsam {
/** Constructor from a Filtered view copies out all values */ /** Constructor from a Filtered view copies out all values */
template<class ValueType> template<class ValueType>
Values::Values(const Values::Filtered<ValueType>& view) { Values::Values(const Values::Filtered<ValueType>& view) {
BOOST_FOREACH(const typename Filtered<ValueType>::KeyValuePair& key_value, view) { for(const typename Filtered<ValueType>::KeyValuePair& key_value: view) {
Key key = key_value.key; Key key = key_value.key;
insert(key, static_cast<const ValueType&>(key_value.value)); insert(key, static_cast<const ValueType&>(key_value.value));
} }
@ -229,7 +227,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
template<class ValueType> template<class ValueType>
Values::Values(const Values::ConstFiltered<ValueType>& view) { Values::Values(const Values::ConstFiltered<ValueType>& view) {
BOOST_FOREACH(const typename ConstFiltered<ValueType>::KeyValuePair& key_value, view) { for(const typename ConstFiltered<ValueType>::KeyValuePair& key_value: view) {
Key key = key_value.key; Key key = key_value.key;
insert(key, static_cast<const ValueType&>(key_value.value)); insert(key, static_cast<const ValueType&>(key_value.value));
} }

View File

@ -25,7 +25,6 @@
#include <gtsam/nonlinear/Values.h> #include <gtsam/nonlinear/Values.h>
#include <gtsam/linear/VectorValues.h> #include <gtsam/linear/VectorValues.h>
#include <boost/foreach.hpp>
#ifdef __GNUC__ #ifdef __GNUC__
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wunused-variable"
@ -194,7 +193,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
size_t Values::dim() const { size_t Values::dim() const {
size_t result = 0; size_t result = 0;
BOOST_FOREACH(const ConstKeyValuePair& key_value, *this) { for(const ConstKeyValuePair& key_value: *this) {
result += key_value.value.dim(); result += key_value.value.dim();
} }
return result; return result;
@ -203,7 +202,7 @@ namespace gtsam {
/* ************************************************************************* */ /* ************************************************************************* */
VectorValues Values::zeroVectors() const { VectorValues Values::zeroVectors() const {
VectorValues result; VectorValues result;
BOOST_FOREACH(const ConstKeyValuePair& key_value, *this) for(const ConstKeyValuePair& key_value: *this)
result.insert(key_value.key, Vector::Zero(key_value.value.dim())); result.insert(key_value.key, Vector::Zero(key_value.value.dim()));
return result; return result;
} }

View File

@ -22,8 +22,6 @@
#include <gtsam/nonlinear/NonlinearFactor.h> #include <gtsam/nonlinear/NonlinearFactor.h>
#include <gtsam/base/numericalDerivative.h> #include <gtsam/base/numericalDerivative.h>
#include <boost/foreach.hpp>
namespace gtsam { namespace gtsam {
/** /**
@ -49,7 +47,7 @@ JacobianFactor linearizeNumerically(const NoiseModelFactor& factor,
// Loop over all variables // Loop over all variables
const double one_over_2delta = 1.0 / (2.0 * delta); const double one_over_2delta = 1.0 / (2.0 * delta);
VectorValues dX = values.zeroVectors(); VectorValues dX = values.zeroVectors();
BOOST_FOREACH(Key key, factor) { for(Key key: factor) {
// Compute central differences using the values struct. // Compute central differences using the values struct.
const size_t cols = dX.dim(key); const size_t cols = dX.dim(key);
Matrix J = Matrix::Zero(rows, cols); Matrix J = Matrix::Zero(rows, cols);

View File

@ -366,7 +366,7 @@ TEST(Values, filter) {
int i = 0; int i = 0;
Values::Filtered<Value> filtered = values.filter(boost::bind(std::greater_equal<Key>(), _1, 2)); Values::Filtered<Value> filtered = values.filter(boost::bind(std::greater_equal<Key>(), _1, 2));
EXPECT_LONGS_EQUAL(2, (long)filtered.size()); EXPECT_LONGS_EQUAL(2, (long)filtered.size());
BOOST_FOREACH(const Values::Filtered<>::KeyValuePair& key_value, filtered) { for(const Values::Filtered<>::KeyValuePair& key_value: filtered) {
if(i == 0) { if(i == 0) {
LONGS_EQUAL(2, (long)key_value.key); LONGS_EQUAL(2, (long)key_value.key);
try {key_value.value.cast<Pose2>();} catch (const std::bad_cast& e) { FAIL("can't cast Value to Pose2");} try {key_value.value.cast<Pose2>();} catch (const std::bad_cast& e) { FAIL("can't cast Value to Pose2");}
@ -401,7 +401,7 @@ TEST(Values, filter) {
i = 0; i = 0;
Values::ConstFiltered<Pose3> pose_filtered = values.filter<Pose3>(); Values::ConstFiltered<Pose3> pose_filtered = values.filter<Pose3>();
EXPECT_LONGS_EQUAL(2, (long)pose_filtered.size()); EXPECT_LONGS_EQUAL(2, (long)pose_filtered.size());
BOOST_FOREACH(const Values::ConstFiltered<Pose3>::KeyValuePair& key_value, pose_filtered) { for(const Values::ConstFiltered<Pose3>::KeyValuePair& key_value: pose_filtered) {
if(i == 0) { if(i == 0) {
EXPECT_LONGS_EQUAL(1, (long)key_value.key); EXPECT_LONGS_EQUAL(1, (long)key_value.key);
EXPECT(assert_equal(pose1, key_value.value)); EXPECT(assert_equal(pose1, key_value.value));
@ -437,7 +437,7 @@ TEST(Values, Symbol_filter) {
values.insert(Symbol('y', 3), pose3); values.insert(Symbol('y', 3), pose3);
int i = 0; int i = 0;
BOOST_FOREACH(const Values::Filtered<Value>::KeyValuePair& key_value, values.filter(Symbol::ChrTest('y'))) { for(const Values::Filtered<Value>::KeyValuePair& key_value: values.filter(Symbol::ChrTest('y'))) {
if(i == 0) { if(i == 0) {
LONGS_EQUAL(Symbol('y', 1), (long)key_value.key); LONGS_EQUAL(Symbol('y', 1), (long)key_value.key);
EXPECT(assert_equal(pose1, key_value.value.cast<Pose3>())); EXPECT(assert_equal(pose1, key_value.value.cast<Pose3>()));

View File

@ -43,7 +43,7 @@ GaussianFactorGraph buildLinearOrientationGraph(const NonlinearFactorGraph& g) {
GaussianFactorGraph linearGraph; GaussianFactorGraph linearGraph;
noiseModel::Unit::shared_ptr model = noiseModel::Unit::Create(9); noiseModel::Unit::shared_ptr model = noiseModel::Unit::Create(9);
BOOST_FOREACH(const boost::shared_ptr<NonlinearFactor>& factor, g) { for(const boost::shared_ptr<NonlinearFactor>& factor: g) {
Matrix3 Rij; Matrix3 Rij;
boost::shared_ptr<BetweenFactor<Pose3> > pose3Between = boost::shared_ptr<BetweenFactor<Pose3> > pose3Between =
@ -75,7 +75,7 @@ Values normalizeRelaxedRotations(const VectorValues& relaxedRot3) {
ppm(0,0) = 1; ppm(1,1) = 1; ppm(2,2) = -1; ppm(0,0) = 1; ppm(1,1) = 1; ppm(2,2) = -1;
Values validRot3; Values validRot3;
BOOST_FOREACH(const VectorValues::value_type& it, relaxedRot3) { for(const VectorValues::value_type& it: relaxedRot3) {
Key key = it.first; Key key = it.first;
if (key != keyAnchor) { if (key != keyAnchor) {
const Vector& rotVector = it.second; const Vector& rotVector = it.second;
@ -108,7 +108,7 @@ NonlinearFactorGraph buildPose3graph(const NonlinearFactorGraph& graph) {
gttic(InitializePose3_buildPose3graph); gttic(InitializePose3_buildPose3graph);
NonlinearFactorGraph pose3Graph; NonlinearFactorGraph pose3Graph;
BOOST_FOREACH(const boost::shared_ptr<NonlinearFactor>& factor, graph) { for(const boost::shared_ptr<NonlinearFactor>& factor: graph) {
// recast to a between on Pose3 // recast to a between on Pose3
boost::shared_ptr<BetweenFactor<Pose3> > pose3Between = boost::shared_ptr<BetweenFactor<Pose3> > pose3Between =
@ -150,7 +150,7 @@ Values computeOrientationsGradient(const NonlinearFactorGraph& pose3Graph, const
// this works on the inverse rotations, according to Tron&Vidal,2011 // this works on the inverse rotations, according to Tron&Vidal,2011
Values inverseRot; Values inverseRot;
inverseRot.insert(keyAnchor, Rot3()); inverseRot.insert(keyAnchor, Rot3());
BOOST_FOREACH(const Values::ConstKeyValuePair& key_value, givenGuess) { for(const Values::ConstKeyValuePair& key_value: givenGuess) {
Key key = key_value.key; Key key = key_value.key;
const Pose3& pose = givenGuess.at<Pose3>(key); const Pose3& pose = givenGuess.at<Pose3>(key);
inverseRot.insert(key, pose.rotation().inverse()); inverseRot.insert(key, pose.rotation().inverse());
@ -165,7 +165,7 @@ Values computeOrientationsGradient(const NonlinearFactorGraph& pose3Graph, const
// calculate max node degree & allocate gradient // calculate max node degree & allocate gradient
size_t maxNodeDeg = 0; size_t maxNodeDeg = 0;
VectorValues grad; VectorValues grad;
BOOST_FOREACH(const Values::ConstKeyValuePair& key_value, inverseRot) { for(const Values::ConstKeyValuePair& key_value: inverseRot) {
Key key = key_value.key; Key key = key_value.key;
grad.insert(key,Vector3::Zero()); grad.insert(key,Vector3::Zero());
size_t currNodeDeg = (adjEdgesMap.at(key)).size(); size_t currNodeDeg = (adjEdgesMap.at(key)).size();
@ -191,12 +191,12 @@ Values computeOrientationsGradient(const NonlinearFactorGraph& pose3Graph, const
//std::cout << "it " << it <<" b " << b <<" f0 " << f0 <<" a " << a //std::cout << "it " << it <<" b " << b <<" f0 " << f0 <<" a " << a
// <<" rho " << rho <<" stepsize " << stepsize << " maxNodeDeg "<< maxNodeDeg << std::endl; // <<" rho " << rho <<" stepsize " << stepsize << " maxNodeDeg "<< maxNodeDeg << std::endl;
maxGrad = 0; maxGrad = 0;
BOOST_FOREACH(const Values::ConstKeyValuePair& key_value, inverseRot) { for(const Values::ConstKeyValuePair& key_value: inverseRot) {
Key key = key_value.key; Key key = key_value.key;
//std::cout << "---------------------------key " << DefaultKeyFormatter(key) << std::endl; //std::cout << "---------------------------key " << DefaultKeyFormatter(key) << std::endl;
Vector gradKey = Vector3::Zero(); Vector gradKey = Vector3::Zero();
// collect the gradient for each edge incident on key // collect the gradient for each edge incident on key
BOOST_FOREACH(const size_t& factorId, adjEdgesMap.at(key)){ for(const size_t& factorId: adjEdgesMap.at(key)){
Rot3 Rij = factorId2RotMap.at(factorId); Rot3 Rij = factorId2RotMap.at(factorId);
Rot3 Ri = inverseRot.at<Rot3>(key); Rot3 Ri = inverseRot.at<Rot3>(key);
if( key == (pose3Graph.at(factorId))->keys()[0] ){ if( key == (pose3Graph.at(factorId))->keys()[0] ){
@ -236,7 +236,7 @@ Values computeOrientationsGradient(const NonlinearFactorGraph& pose3Graph, const
// Return correct rotations // Return correct rotations
const Rot3& Rref = inverseRot.at<Rot3>(keyAnchor); // This will be set to the identity as so far we included no prior const Rot3& Rref = inverseRot.at<Rot3>(keyAnchor); // This will be set to the identity as so far we included no prior
Values estimateRot; Values estimateRot;
BOOST_FOREACH(const Values::ConstKeyValuePair& key_value, inverseRot) { for(const Values::ConstKeyValuePair& key_value: inverseRot) {
Key key = key_value.key; Key key = key_value.key;
if (key != keyAnchor) { if (key != keyAnchor) {
const Rot3& R = inverseRot.at<Rot3>(key); const Rot3& R = inverseRot.at<Rot3>(key);
@ -252,7 +252,7 @@ Values computeOrientationsGradient(const NonlinearFactorGraph& pose3Graph, const
/* ************************************************************************* */ /* ************************************************************************* */
void createSymbolicGraph(KeyVectorMap& adjEdgesMap, KeyRotMap& factorId2RotMap, const NonlinearFactorGraph& pose3Graph){ void createSymbolicGraph(KeyVectorMap& adjEdgesMap, KeyRotMap& factorId2RotMap, const NonlinearFactorGraph& pose3Graph){
size_t factorId = 0; size_t factorId = 0;
BOOST_FOREACH(const boost::shared_ptr<NonlinearFactor>& factor, pose3Graph) { for(const boost::shared_ptr<NonlinearFactor>& factor: pose3Graph) {
boost::shared_ptr<BetweenFactor<Pose3> > pose3Between = boost::shared_ptr<BetweenFactor<Pose3> > pose3Between =
boost::dynamic_pointer_cast<BetweenFactor<Pose3> >(factor); boost::dynamic_pointer_cast<BetweenFactor<Pose3> >(factor);
if (pose3Between){ if (pose3Between){
@ -321,7 +321,7 @@ Values computePoses(NonlinearFactorGraph& pose3graph, Values& initialRot) {
// put into Values structure // put into Values structure
Values initialPose; Values initialPose;
BOOST_FOREACH(const Values::ConstKeyValuePair& key_value, initialRot){ for(const Values::ConstKeyValuePair& key_value: initialRot){
Key key = key_value.key; Key key = key_value.key;
const Rot3& rot = initialRot.at<Rot3>(key); const Rot3& rot = initialRot.at<Rot3>(key);
Pose3 initializedPose = Pose3(rot, Point3(0, 0, 0)); Pose3 initializedPose = Pose3(rot, Point3(0, 0, 0));
@ -346,7 +346,7 @@ Values computePoses(NonlinearFactorGraph& pose3graph, Values& initialRot) {
// put into Values structure // put into Values structure
Values estimate; Values estimate;
BOOST_FOREACH(const Values::ConstKeyValuePair& key_value, GNresult) { for(const Values::ConstKeyValuePair& key_value: GNresult) {
Key key = key_value.key; Key key = key_value.key;
if (key != keyAnchor) { if (key != keyAnchor) {
const Pose3& pose = GNresult.at<Pose3>(key); const Pose3& pose = GNresult.at<Pose3>(key);
@ -391,7 +391,7 @@ Values initialize(const NonlinearFactorGraph& graph, const Values& givenGuess, b
// Compute the full poses (1 GN iteration on full poses) // Compute the full poses (1 GN iteration on full poses)
return computePoses(pose3Graph, orientations); return computePoses(pose3Graph, orientations);
// BOOST_FOREACH(const Values::ConstKeyValuePair& key_value, orientations) { // for(const Values::ConstKeyValuePair& key_value: orientations) {
// Key key = key_value.key; // Key key = key_value.key;
// if (key != keyAnchor) { // if (key != keyAnchor) {
// const Point3& pos = givenGuess.at<Pose3>(key).translation(); // const Point3& pos = givenGuess.at<Pose3>(key).translation();

View File

@ -44,7 +44,7 @@ public:
Vector zeroVector = Vector::Zero(0); Vector zeroVector = Vector::Zero(0);
std::vector<KeyMatrix> QF; std::vector<KeyMatrix> QF;
QF.reserve(keys.size()); QF.reserve(keys.size());
BOOST_FOREACH(const Key& key, keys) for(const Key& key: keys)
QF.push_back(KeyMatrix(key, zeroMatrix)); QF.push_back(KeyMatrix(key, zeroMatrix));
JacobianFactor::fillTerms(QF, zeroVector, model); JacobianFactor::fillTerms(QF, zeroVector, model);
} }

View File

@ -45,7 +45,7 @@ public:
Vector zeroVector = Vector::Zero(0); Vector zeroVector = Vector::Zero(0);
std::vector<KeyMatrix> QF; std::vector<KeyMatrix> QF;
QF.reserve(keys.size()); QF.reserve(keys.size());
BOOST_FOREACH(const Key& key, keys) for(const Key& key: keys)
QF.push_back(KeyMatrix(key, zeroMatrix)); QF.push_back(KeyMatrix(key, zeroMatrix));
JacobianFactor::fillTerms(QF, zeroVector, model); JacobianFactor::fillTerms(QF, zeroVector, model);
} }
@ -67,7 +67,7 @@ public:
size_t m2 = ZDim * numKeys - 3; // TODO: is this not just Enull.rows()? size_t m2 = ZDim * numKeys - 3; // TODO: is this not just Enull.rows()?
// PLAIN NULL SPACE TRICK // PLAIN NULL SPACE TRICK
// Matrix Q = Enull * Enull.transpose(); // Matrix Q = Enull * Enull.transpose();
// BOOST_FOREACH(const KeyMatrixZD& it, Fblocks) // for(const KeyMatrixZD& it: Fblocks)
// QF.push_back(KeyMatrix(it.first, Q.block(0, 2 * j++, m2, 2) * it.second)); // QF.push_back(KeyMatrix(it.first, Q.block(0, 2 * j++, m2, 2) * it.second));
// JacobianFactor factor(QF, Q * b); // JacobianFactor factor(QF, Q * b);
std::vector<KeyMatrix> QF; std::vector<KeyMatrix> QF;

View File

@ -10,7 +10,6 @@
#include <gtsam/geometry/CameraSet.h> #include <gtsam/geometry/CameraSet.h>
#include <gtsam/linear/JacobianFactor.h> #include <gtsam/linear/JacobianFactor.h>
#include <gtsam/linear/VectorValues.h> #include <gtsam/linear/VectorValues.h>
#include <boost/foreach.hpp>
#include <iosfwd> #include <iosfwd>
namespace gtsam { namespace gtsam {

View File

@ -161,7 +161,7 @@ public:
/// Collect all cameras: important that in key order /// Collect all cameras: important that in key order
virtual Cameras cameras(const Values& values) const { virtual Cameras cameras(const Values& values) const {
Cameras cameras; Cameras cameras;
BOOST_FOREACH(const Key& k, this->keys_) for(const Key& k: this->keys_)
cameras.push_back(values.at<CAMERA>(k)); cameras.push_back(values.at<CAMERA>(k));
return cameras; return cameras;
} }

Some files were not shown because too many files have changed in this diff Show More