Switched to using c++11 braces-style initialization

release/4.3a0
dellaert 2018-11-08 17:18:47 -05:00
parent 8f83791bb6
commit 79fe89eaa9
20 changed files with 43 additions and 95 deletions

View File

@ -22,8 +22,7 @@ using namespace gtsam;
/* ************************************************************************* */
TEST( testFastContainers, KeySet ) {
KeyVector init_vector;
init_vector += 2, 3, 4, 5;
KeyVector init_vector {2, 3, 4, 5};
KeySet actSet(init_vector);
KeySet expSet; expSet += 2, 3, 4, 5;

View File

@ -93,18 +93,12 @@ TEST(CameraSet, Pinhole) {
EXPECT(assert_equal(schur, actualReduced.selfadjointView()));
// Check Schur complement update, same order, should just double
KeyVector allKeys, keys;
allKeys.push_back(1);
allKeys.push_back(2);
keys.push_back(1);
keys.push_back(2);
KeyVector allKeys {1, 2}, keys {1, 2};
Set::UpdateSchurComplement(Fs, E, P, b, allKeys, keys, actualReduced);
EXPECT(assert_equal((Matrix )(2.0 * schur), actualReduced.selfadjointView()));
// Check Schur complement update, keys reversed
KeyVector keys2;
keys2.push_back(2);
keys2.push_back(1);
KeyVector keys2 {2, 1};
Set::UpdateSchurComplement(Fs, E, P, b, allKeys, keys2, actualReduced);
Vector4 reverse_b;
reverse_b << b.tail<2>(), b.head<2>();

View File

@ -229,7 +229,7 @@ TEST(GaussianBayesNet, ComputeSteepestDescentPoint) {
VectorValues actual = gbn.optimizeGradientSearch();
// Check that points agree
KeyVector keys = list_of(0)(1)(2)(3)(4);
KeyVector keys {0, 1, 2, 3, 4};
Vector actualAsVector = actual.vector(keys);
EXPECT(assert_equal(expected, actualAsVector, 1e-5));

View File

@ -287,7 +287,7 @@ TEST(GaussianBayesTree, ComputeSteepestDescentPointBT) {
VectorValues actual = bt.optimizeGradientSearch();
// Check that points agree
KeyVector keys = list_of(0)(1)(2)(3)(4);
KeyVector keys {0, 1, 2, 3, 4};
EXPECT(assert_equal(expected, actual.vector(keys), 1e-5));
EXPECT(assert_equal(expectedFromBN, actual, 1e-5));

View File

@ -41,7 +41,7 @@ const double tol = 1e-5;
/* ************************************************************************* */
TEST(HessianFactor, Slot)
{
KeyVector keys = list_of(2)(4)(1);
KeyVector keys {2, 4, 1};
EXPECT_LONGS_EQUAL(0, GaussianFactor::Slot(keys,2));
EXPECT_LONGS_EQUAL(1, GaussianFactor::Slot(keys,4));
EXPECT_LONGS_EQUAL(2, GaussianFactor::Slot(keys,1));
@ -252,8 +252,7 @@ TEST(HessianFactor, ConstructorNWay)
(1, dx1)
(2, dx2);
KeyVector js;
js.push_back(0); js.push_back(1); js.push_back(2);
KeyVector js {0, 1, 2};
std::vector<Matrix> Gs;
Gs.push_back(G11); Gs.push_back(G12); Gs.push_back(G13); Gs.push_back(G22); Gs.push_back(G23); Gs.push_back(G33);
std::vector<Vector> gs;
@ -517,7 +516,7 @@ TEST(HessianFactor, gradientAtZero)
// test gradient at zero
VectorValues expectedG = pair_list_of<Key, Vector>(0, -g1) (1, -g2);
Matrix A; Vector b; boost::tie(A,b) = factor.jacobian();
KeyVector keys; keys += 0,1;
KeyVector keys {0, 1};
EXPECT(assert_equal(-A.transpose()*b, expectedG.vector(keys)));
VectorValues actualG = factor.gradientAtZero();
EXPECT(assert_equal(expectedG, actualG));

View File

@ -350,7 +350,7 @@ TEST(JacobianFactor, operators )
VectorValues expectedG;
expectedG.insert(1, Vector2(20,-10));
expectedG.insert(2, Vector2(-20, 10));
KeyVector keys; keys += 1,2;
KeyVector keys {1, 2};
EXPECT(assert_equal(-A.transpose()*b2, expectedG.vector(keys)));
VectorValues actualG = lf.gradientAtZero();
EXPECT(assert_equal(expectedG, actualG));

View File

@ -64,7 +64,7 @@ TEST(RegularHessianFactor, Constructors)
EXPECT(assert_equal(factor,factor2));
// Test n-way constructor
KeyVector keys; keys += 0, 1, 3;
KeyVector keys {0, 1, 3};
vector<Matrix> Gs; Gs += G11, G12, G13, G22, G23, G33;
vector<Vector> gs; gs += g1, g2, g3;
RegularHessianFactor<2> factor3(keys, Gs, gs, f);

View File

@ -62,7 +62,7 @@ TEST(VectorValues, basics)
EXPECT(assert_equal(Vector2(2, 3), actual[1]));
EXPECT(assert_equal(Vector2(4, 5), actual[2]));
EXPECT(assert_equal(Vector2(6, 7), actual[5]));
KeyVector keys = list_of(0)(1)(2)(5);
KeyVector keys {0, 1, 2, 5};
EXPECT(assert_equal((Vector(7) << 1, 2, 3, 4, 5, 6, 7).finished(), actual.vector(keys)));
// Check exceptions
@ -101,8 +101,7 @@ TEST(VectorValues, subvector)
init.insert(12, Vector2(4, 5));
init.insert(13, Vector2(6, 7));
KeyVector keys;
keys += 10, 12, 13;
KeyVector keys {10, 12, 13};
Vector expSubVector = (Vector(5) << 1, 4, 5, 6, 7).finished();
EXPECT(assert_equal(expSubVector, init.vector(keys)));
}
@ -197,7 +196,7 @@ TEST(VectorValues, convert)
EXPECT(assert_equal(expected, actual2));
// Test other direction, note vector() is not guaranteed to give right result
KeyVector keys = list_of(0)(1)(2)(5);
KeyVector keys {0, 1, 2, 5};
EXPECT(assert_equal(x, actual.vector(keys)));
// Test version with dims argument
@ -222,7 +221,7 @@ TEST(VectorValues, vector_sub)
expected << 1, 6, 7;
// Test FastVector version
KeyVector keys = list_of(0)(5);
KeyVector keys {0, 5};
EXPECT(assert_equal(expected, vv.vector(keys)));
// Test version with dims argument

View File

@ -23,6 +23,8 @@
#include <gtsam/base/types.h>
#include <CppUnitLite/TestHarness.h>
#include <boost/algorithm/string.hpp>
#include <string>
#include <iostream>
using namespace std;
@ -68,7 +70,9 @@ TEST( GeographicLib, UTM) {
// UTM is 16N 749305.58 3751090.08
// Obtained by
// http://geographiclib.sourceforge.net/cgi-bin/GeoConvert?input=33.87071+-84.30482000000001&zone=-3&prec=2&option=Submit
EXPECT(UTMUPS::EncodeZone(zone, northp)=="16N");
auto actual = UTMUPS::EncodeZone(zone, northp);
boost::to_upper(actual);
EXPECT(actual=="16N");
EXPECT_DOUBLES_EQUAL(749305.58, x, 1e-2);
EXPECT_DOUBLES_EQUAL(3751090.08, y, 1e-2);
}

View File

@ -47,8 +47,7 @@ TEST( testLinearContainerFactor, generic_jacobian_factor ) {
EXPECT(!actFactor.isHessian());
// check keys
KeyVector expKeys; expKeys += l1, l2;
EXPECT(assert_container_equality(expKeys, actFactor.keys()));
EXPECT(assert_container_equality({l1, l2}, actFactor.keys()));
Values values;
values.insert(l1, landmark1);
@ -246,9 +245,7 @@ TEST( testLinearContainerFactor, creation ) {
LinearContainerFactor actual(linear_factor, full_values);
// Verify the keys
KeyVector expKeys;
expKeys += l3, l5;
EXPECT(assert_container_equality(expKeys, actual.keys()));
EXPECT(assert_container_equality({l3, l5}, actual.keys()));
// Verify subset of linearization points
EXPECT(assert_equal(exp_values, actual.linearizationPoint(), tol));

View File

@ -279,9 +279,8 @@ TEST(Values, extract_keys)
config.insert(key3, Pose2());
config.insert(key4, Pose2());
KeyVector expected, actual;
expected += key1, key2, key3, key4;
actual = config.keys();
KeyVector expected {key1, key2, key3, key4};
KeyVector actual = config.keys();
CHECK(actual.size() == expected.size());
KeyVector::const_iterator itAct = actual.begin(), itExp = expected.begin();

View File

@ -102,9 +102,7 @@ TEST( RangeFactor, ConstructorWithTransform) {
RangeFactorWithTransform2D factor2D(poseKey, pointKey, measurement, model,
body_P_sensor_2D);
KeyVector expected;
expected.push_back(2);
expected.push_back(1);
KeyVector expected {2, 1};
CHECK(factor2D.keys() == expected);
RangeFactorWithTransform3D factor3D(poseKey, pointKey, measurement, model,
body_P_sensor_3D);

View File

@ -42,7 +42,7 @@ const Matrix26 F0 = Matrix26::Ones();
const Matrix26 F1 = 2 * Matrix26::Ones();
const Matrix26 F3 = 3 * Matrix26::Ones();
const vector<Matrix26, Eigen::aligned_allocator<Matrix26> > FBlocks = list_of<Matrix26>(F0)(F1)(F3);
const KeyVector keys = list_of<Key>(0)(1)(3);
const KeyVector keys {0, 1, 3};
// RHS and sigmas
const Vector b = (Vector(6) << 1., 2., 3., 4., 5., 6.).finished();
@ -86,8 +86,7 @@ TEST( regularImplicitSchurFactor, addHessianMultiply ) {
F << F0, Matrix::Zero(2, d * 3), Matrix::Zero(2, d), F1, Matrix::Zero(2, d*2), Matrix::Zero(2, d * 3), F3;
// Calculate expected result F'*alpha*(I - E*P*E')*F*x
KeyVector keys2;
keys2 += 0,1,2,3;
KeyVector keys2{0,1,2,3};
Vector x = xvalues.vector(keys2);
Vector expected = Vector::Zero(24);
RegularImplicitSchurFactor<CalibratedCamera>::multiplyHessianAdd(F, E, P, alpha, x, expected);

View File

@ -170,9 +170,7 @@ TEST( SmartProjectionCameraFactor, noisy ) {
measurements.push_back(level_uv);
measurements.push_back(level_uv_right);
KeyVector views;
views.push_back(c1);
views.push_back(c2);
KeyVector views {c1, c2};
factor2->add(measurements, views);
@ -195,10 +193,7 @@ TEST( SmartProjectionCameraFactor, perturbPoseAndOptimize ) {
SmartFactor::shared_ptr smartFactor1(new SmartFactor(unit2));
SmartFactor::shared_ptr smartFactor2(new SmartFactor(unit2));
SmartFactor::shared_ptr smartFactor3(new SmartFactor(unit2));
KeyVector views;
views.push_back(c1);
views.push_back(c2);
views.push_back(c3);
KeyVector views {c1, c2, c3};
smartFactor1->add(measurements_cam1, views);
smartFactor2->add(measurements_cam2, views);
smartFactor3->add(measurements_cam3, views);
@ -293,10 +288,7 @@ TEST( SmartProjectionCameraFactor, perturbPoseAndOptimizeFromSfM_tracks ) {
projectToMultipleCameras(cam1, cam2, cam3, landmark2, measurements_cam2);
projectToMultipleCameras(cam1, cam2, cam3, landmark3, measurements_cam3);
KeyVector views;
views.push_back(c1);
views.push_back(c2);
views.push_back(c3);
KeyVector views {c1, c2, c3};
SfM_Track track1;
for (size_t i = 0; i < 3; ++i) {
@ -370,10 +362,7 @@ TEST( SmartProjectionCameraFactor, perturbCamerasAndOptimize ) {
projectToMultipleCameras(cam1, cam2, cam3, landmark4, measurements_cam4);
projectToMultipleCameras(cam1, cam2, cam3, landmark5, measurements_cam5);
KeyVector views;
views.push_back(c1);
views.push_back(c2);
views.push_back(c3);
KeyVector views {c1, c2, c3};
SmartFactor::shared_ptr smartFactor1(new SmartFactor(unit2));
smartFactor1->add(measurements_cam1, views);
@ -450,10 +439,7 @@ TEST( SmartProjectionCameraFactor, Cal3Bundler ) {
projectToMultipleCameras(cam1, cam2, cam3, landmark4, measurements_cam4);
projectToMultipleCameras(cam1, cam2, cam3, landmark5, measurements_cam5);
KeyVector views;
views.push_back(c1);
views.push_back(c2);
views.push_back(c3);
KeyVector views {c1, c2, c3};
SmartFactor::shared_ptr smartFactor1(new SmartFactor(unit2));
smartFactor1->add(measurements_cam1, views);
@ -526,10 +512,7 @@ TEST( SmartProjectionCameraFactor, Cal3Bundler2 ) {
projectToMultipleCameras(cam1, cam2, cam3, landmark4, measurements_cam4);
projectToMultipleCameras(cam1, cam2, cam3, landmark5, measurements_cam5);
KeyVector views;
views.push_back(c1);
views.push_back(c2);
views.push_back(c3);
KeyVector views {c1, c2, c3};
SmartFactor::shared_ptr smartFactor1(new SmartFactor(unit2));
smartFactor1->add(measurements_cam1, views);

View File

@ -81,10 +81,7 @@ TEST( SymbolicBayesNet, combine )
TEST(SymbolicBayesNet, saveGraph) {
SymbolicBayesNet bn;
bn += SymbolicConditional(_A_, _B_);
KeyVector keys;
keys.push_back(_B_);
keys.push_back(_C_);
keys.push_back(_D_);
KeyVector keys {_B_, _C_, _D_};
bn += SymbolicConditional::FromKeys(keys,2);
bn += SymbolicConditional(_D_);

View File

@ -33,7 +33,7 @@ using namespace boost::assign;
/* ************************************************************************* */
#ifdef TRACK_ELIMINATE
TEST(SymbolicFactor, eliminate) {
KeyVector keys; keys += 2, 3, 4, 6, 7, 9, 10, 11;
KeyVector keys {2, 3, 4, 6, 7, 9, 10, 11};
IndexFactor actual(keys.begin(), keys.end());
BayesNet<IndexConditional> fragment = *actual.eliminate(3);

View File

@ -419,9 +419,7 @@ TEST( ConcurrentBatchFilter, update_and_marginalize )
ordering.push_back(3);
// Create the set of marginalizable variables
KeyVector linearIndices;
linearIndices.push_back(1);
linearIndices.push_back(2);
KeyVector linearIndices {1, 2};
GaussianFactorGraph linearPartialGraph = *partialGraph.linearize(partialValues);
GaussianFactorGraph result = *linearPartialGraph.eliminatePartialMultifrontal(linearIndices, EliminateCholesky).second;
@ -1008,8 +1006,7 @@ TEST( ConcurrentBatchFilter, CalculateMarginals_1 )
GaussianFactorGraph linearFactorGraph = *factorGraph.linearize(newValues);
// Create the set of marginalizable variables
KeyVector linearIndices;
linearIndices.push_back(1);
KeyVector linearIndices {1};
GaussianFactorGraph result = *linearFactorGraph.eliminatePartialMultifrontal(linearIndices, EliminateCholesky).second;
@ -1062,9 +1059,7 @@ TEST( ConcurrentBatchFilter, CalculateMarginals_2 )
GaussianFactorGraph linearFactorGraph = *factorGraph.linearize(newValues);
// Create the set of marginalizable variables
KeyVector linearIndices;
linearIndices.push_back(1);
linearIndices.push_back(2);
KeyVector linearIndices {1, 2};
GaussianFactorGraph result = *linearFactorGraph.eliminatePartialMultifrontal(linearIndices, EliminateCholesky).second;

View File

@ -1108,12 +1108,9 @@ TEST( ConcurrentIncrementalFilter, CalculateMarginals_1 )
newValues.insert(3, value3);
// Create the set of marginalizable variables
KeyVector linearIndices;
linearIndices.push_back(1);
GaussianFactorGraph linearGraph = *factorGraph.linearize(newValues);
GaussianFactorGraph marginal = *linearGraph.eliminatePartialMultifrontal(KeyVector(linearIndices.begin(), linearIndices.end()), EliminateCholesky).second;
GaussianFactorGraph marginal = *linearGraph.eliminatePartialMultifrontal({1}, EliminateCholesky).second;
NonlinearFactorGraph expectedMarginals;
for(const GaussianFactor::shared_ptr& factor: marginal) {
@ -1156,15 +1153,10 @@ TEST( ConcurrentIncrementalFilter, CalculateMarginals_2 )
newValues.insert(3, value3);
// Create the set of marginalizable variables
KeyVector linearIndices;
linearIndices.push_back(1);
linearIndices.push_back(2);
// Create the set of marginalizable variables
KeyVector linearIndices {1, 2};
GaussianFactorGraph linearGraph = *factorGraph.linearize(newValues);
GaussianFactorGraph marginal = *linearGraph.eliminatePartialMultifrontal(KeyVector(linearIndices.begin(), linearIndices.end()), EliminateCholesky).second;
GaussianFactorGraph marginal = *linearGraph.eliminatePartialMultifrontal(linearIndices, EliminateCholesky).second;
NonlinearFactorGraph expectedMarginals;
for(const GaussianFactor::shared_ptr& factor: marginal) {

View File

@ -139,10 +139,7 @@ TEST(Marginals, planarSLAMmarginals) {
0.151935669757191, 0.007741936219615, 0.090000180000270, -0.000000000000000, 0.000000000000000, 0.160967924878730, 0.007741936219615, 0.004516127560770,
-0.104516127560770, 0.351935664055174, 0.000000000000000, 0.090000180000270, 0.040000000000000, 0.007741936219615, 0.351935664055174, 0.056129031890193,
-0.050967744878460, 0.056129031890193, 0.000000000000000, 0.000000000000000, 0.010000000000000, 0.004516127560770, 0.056129031890193, 0.027741936219615;
KeyVector variables(3);
variables[0] = x1;
variables[1] = l2;
variables[2] = x3;
KeyVector variables {x1, l2, x3};
JointMarginal joint_l2x1x3 = marginals.jointMarginalCovariance(variables);
EXPECT(assert_equal(Matrix(expected_l2x1x3.block(0,0,2,2)), Matrix(joint_l2x1x3(l2,l2)), 1e-6));
EXPECT(assert_equal(Matrix(expected_l2x1x3.block(2,0,3,2)), Matrix(joint_l2x1x3(x1,l2)), 1e-6));

View File

@ -401,11 +401,7 @@ TEST( NonlinearFactor, clone_rekey )
EXPECT(assert_equal(*init, *actClone));
// Re-key factor - clones with different keys
KeyVector new_keys(4);
new_keys[0] = X(5);
new_keys[1] = X(6);
new_keys[2] = X(7);
new_keys[3] = X(8);
KeyVector new_keys {X(5),X(6),X(7),X(8)};
shared_nlf actRekey = init->rekey(new_keys);
EXPECT(actRekey.get() != init.get()); // Ensure different pointers