Skip to content

Commit

Permalink
Merge pull request #1375 from borglab/feature/Ordering_initializers
Browse files Browse the repository at this point in the history
  • Loading branch information
dellaert authored Jan 10, 2023
2 parents b882eaf + d41d4c2 commit f7c6f2b
Show file tree
Hide file tree
Showing 129 changed files with 1,432 additions and 1,784 deletions.
3 changes: 0 additions & 3 deletions examples/CreateSFMExampleData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
#include <gtsam/geometry/CalibratedCamera.h>
#include <gtsam/slam/dataset.h>

#include <boost/assign/std/vector.hpp>

using namespace boost::assign;
using namespace std;
using namespace gtsam;

Expand Down
2 changes: 0 additions & 2 deletions examples/TimeTBB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
#include <gtsam/global_includes.h>
#include <gtsam/base/Matrix.h>

#include <boost/assign/list_of.hpp>
#include <map>
#include <iostream>

using namespace std;
using namespace gtsam;
using boost::assign::list_of;

#ifdef GTSAM_USE_TBB

Expand Down
3 changes: 3 additions & 0 deletions gtsam/base/FastList.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class FastList: public std::list<VALUE, typename internal::FastDefaultAllocator<
/** Copy constructor from the base list class */
FastList(const Base& x) : Base(x) {}

/// Construct from c++11 initializer list:
FastList(std::initializer_list<VALUE> l) : Base(l) {}

#ifdef GTSAM_ALLOCATOR_BOOSTPOOL
/** Copy constructor from a standard STL container */
FastList(const std::list<VALUE>& x) {
Expand Down
10 changes: 2 additions & 8 deletions gtsam/base/FastSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,9 @@ class FastSet: public std::set<VALUE, std::less<VALUE>,
typedef std::set<VALUE, std::less<VALUE>,
typename internal::FastDefaultAllocator<VALUE>::type> Base;

/** Default constructor */
FastSet() {
}
using Base::Base; // Inherit the set constructors

/** Constructor from a range, passes through to base class */
template<typename INPUTITERATOR>
explicit FastSet(INPUTITERATOR first, INPUTITERATOR last) :
Base(first, last) {
}
FastSet() = default; ///< Default constructor

/** Constructor from a iterable container, passes through to base class */
template<typename INPUTCONTAINER>
Expand Down
45 changes: 15 additions & 30 deletions gtsam/base/tests/testDSFMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@
* @brief unit tests for DSFMap
*/

#include <gtsam/base/DSFMap.h>

#include <boost/assign/std/list.hpp>
#include <boost/assign/std/set.hpp>
using namespace boost::assign;

#include <CppUnitLite/TestHarness.h>
#include <gtsam/base/DSFMap.h>

#include <iostream>
#include <list>
#include <map>
#include <set>

using namespace std;
using namespace gtsam;

/* ************************************************************************* */
Expand Down Expand Up @@ -65,9 +62,8 @@ TEST(DSFMap, merge3) {
TEST(DSFMap, mergePairwiseMatches) {

// Create some "matches"
typedef pair<size_t,size_t> Match;
list<Match> matches;
matches += Match(1,2), Match(2,3), Match(4,5), Match(4,6);
typedef std::pair<size_t, size_t> Match;
const std::list<Match> matches{{1, 2}, {2, 3}, {4, 5}, {4, 6}};

// Merge matches
DSFMap<size_t> dsf;
Expand All @@ -86,18 +82,17 @@ TEST(DSFMap, mergePairwiseMatches) {
TEST(DSFMap, mergePairwiseMatches2) {

// Create some measurements with image index and feature index
typedef pair<size_t,size_t> Measurement;
typedef std::pair<size_t,size_t> Measurement;
Measurement m11(1,1),m12(1,2),m14(1,4); // in image 1
Measurement m22(2,2),m23(2,3),m25(2,5),m26(2,6); // in image 2

// Add them all
list<Measurement> measurements;
measurements += m11,m12,m14, m22,m23,m25,m26;
const std::list<Measurement> measurements{m11, m12, m14, m22, m23, m25, m26};

// Create some "matches"
typedef pair<Measurement,Measurement> Match;
list<Match> matches;
matches += Match(m11,m22), Match(m12,m23), Match(m14,m25), Match(m14,m26);
typedef std::pair<Measurement, Measurement> Match;
const std::list<Match> matches{
{m11, m22}, {m12, m23}, {m14, m25}, {m14, m26}};

// Merge matches
DSFMap<Measurement> dsf;
Expand All @@ -114,26 +109,16 @@ TEST(DSFMap, mergePairwiseMatches2) {
/* ************************************************************************* */
TEST(DSFMap, sets){
// Create some "matches"
typedef pair<size_t,size_t> Match;
list<Match> matches;
matches += Match(1,2), Match(2,3), Match(4,5), Match(4,6);
using Match = std::pair<size_t,size_t>;
const std::list<Match> matches{{1, 2}, {2, 3}, {4, 5}, {4, 6}};

// Merge matches
DSFMap<size_t> dsf;
for(const Match& m: matches)
dsf.merge(m.first,m.second);

map<size_t, set<size_t> > sets = dsf.sets();
set<size_t> s1, s2;
s1 += 1,2,3;
s2 += 4,5,6;

/*for(key_pair st: sets){
cout << "Set " << st.first << " :{";
for(const size_t s: st.second)
cout << s << ", ";
cout << "}" << endl;
}*/
std::map<size_t, std::set<size_t> > sets = dsf.sets();
const std::set<size_t> s1{1, 2, 3}, s2{4, 5, 6};

EXPECT(s1 == sets[1]);
EXPECT(s2 == sets[4]);
Expand Down
60 changes: 30 additions & 30 deletions gtsam/base/tests/testDSFVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
#include <CppUnitLite/TestHarness.h>

#include <boost/make_shared.hpp>
#include <boost/assign/std/list.hpp>
#include <boost/assign/std/set.hpp>
#include <boost/assign/std/vector.hpp>
using namespace boost::assign;

#include <iostream>
#include <set>
#include <list>
#include <utility>

using namespace std;
using std::pair;
using std::map;
using std::vector;
using namespace gtsam;

/* ************************************************************************* */
Expand Down Expand Up @@ -64,8 +65,8 @@ TEST(DSFBase, mergePairwiseMatches) {

// Create some "matches"
typedef pair<size_t,size_t> Match;
vector<Match> matches;
matches += Match(1,2), Match(2,3), Match(4,5), Match(4,6);
const vector<Match> matches{Match(1, 2), Match(2, 3), Match(4, 5),
Match(4, 6)};

// Merge matches
DSFBase dsf(7); // We allow for keys 0..6
Expand All @@ -85,7 +86,7 @@ TEST(DSFBase, mergePairwiseMatches) {
/* ************************************************************************* */
TEST(DSFVector, merge2) {
boost::shared_ptr<DSFBase::V> v = boost::make_shared<DSFBase::V>(5);
std::vector<size_t> keys; keys += 1, 3;
const std::vector<size_t> keys {1, 3};
DSFVector dsf(v, keys);
dsf.merge(1,3);
EXPECT(dsf.find(1) == dsf.find(3));
Expand All @@ -95,10 +96,10 @@ TEST(DSFVector, merge2) {
TEST(DSFVector, sets) {
DSFVector dsf(2);
dsf.merge(0,1);
map<size_t, set<size_t> > sets = dsf.sets();
map<size_t, std::set<size_t> > sets = dsf.sets();
LONGS_EQUAL(1, sets.size());

set<size_t> expected; expected += 0, 1;
const std::set<size_t> expected{0, 1};
EXPECT(expected == sets[dsf.find(0)]);
}

Expand All @@ -109,7 +110,7 @@ TEST(DSFVector, arrays) {
map<size_t, vector<size_t> > arrays = dsf.arrays();
LONGS_EQUAL(1, arrays.size());

vector<size_t> expected; expected += 0, 1;
const vector<size_t> expected{0, 1};
EXPECT(expected == arrays[dsf.find(0)]);
}

Expand All @@ -118,10 +119,10 @@ TEST(DSFVector, sets2) {
DSFVector dsf(3);
dsf.merge(0,1);
dsf.merge(1,2);
map<size_t, set<size_t> > sets = dsf.sets();
map<size_t, std::set<size_t> > sets = dsf.sets();
LONGS_EQUAL(1, sets.size());

set<size_t> expected; expected += 0, 1, 2;
const std::set<size_t> expected{0, 1, 2};
EXPECT(expected == sets[dsf.find(0)]);
}

Expand All @@ -133,18 +134,18 @@ TEST(DSFVector, arrays2) {
map<size_t, vector<size_t> > arrays = dsf.arrays();
LONGS_EQUAL(1, arrays.size());

vector<size_t> expected; expected += 0, 1, 2;
const vector<size_t> expected{0, 1, 2};
EXPECT(expected == arrays[dsf.find(0)]);
}

/* ************************************************************************* */
TEST(DSFVector, sets3) {
DSFVector dsf(3);
dsf.merge(0,1);
map<size_t, set<size_t> > sets = dsf.sets();
map<size_t, std::set<size_t> > sets = dsf.sets();
LONGS_EQUAL(2, sets.size());

set<size_t> expected; expected += 0, 1;
const std::set<size_t> expected{0, 1};
EXPECT(expected == sets[dsf.find(0)]);
}

Expand All @@ -155,18 +156,18 @@ TEST(DSFVector, arrays3) {
map<size_t, vector<size_t> > arrays = dsf.arrays();
LONGS_EQUAL(2, arrays.size());

vector<size_t> expected; expected += 0, 1;
const vector<size_t> expected{0, 1};
EXPECT(expected == arrays[dsf.find(0)]);
}

/* ************************************************************************* */
TEST(DSFVector, set) {
DSFVector dsf(3);
dsf.merge(0,1);
set<size_t> set = dsf.set(0);
std::set<size_t> set = dsf.set(0);
LONGS_EQUAL(2, set.size());

std::set<size_t> expected; expected += 0, 1;
const std::set<size_t> expected{0, 1};
EXPECT(expected == set);
}

Expand All @@ -175,10 +176,10 @@ TEST(DSFVector, set2) {
DSFVector dsf(3);
dsf.merge(0,1);
dsf.merge(1,2);
set<size_t> set = dsf.set(0);
std::set<size_t> set = dsf.set(0);
LONGS_EQUAL(3, set.size());

std::set<size_t> expected; expected += 0, 1, 2;
const std::set<size_t> expected{0, 1, 2};
EXPECT(expected == set);
}

Expand All @@ -195,27 +196,26 @@ TEST(DSFVector, isSingleton) {
TEST(DSFVector, mergePairwiseMatches) {

// Create some measurements
vector<size_t> keys;
keys += 1,2,3,4,5,6;
const vector<size_t> keys{1, 2, 3, 4, 5, 6};

// Create some "matches"
typedef pair<size_t,size_t> Match;
vector<Match> matches;
matches += Match(1,2), Match(2,3), Match(4,5), Match(4,6);
const vector<Match> matches{Match(1, 2), Match(2, 3), Match(4, 5),
Match(4, 6)};

// Merge matches
DSFVector dsf(keys);
for(const Match& m: matches)
dsf.merge(m.first,m.second);

// Check that we have two connected components, 1,2,3 and 4,5,6
map<size_t, set<size_t> > sets = dsf.sets();
map<size_t, std::set<size_t> > sets = dsf.sets();
LONGS_EQUAL(2, sets.size());
set<size_t> expected1; expected1 += 1,2,3;
set<size_t> actual1 = sets[dsf.find(2)];
const std::set<size_t> expected1{1, 2, 3};
std::set<size_t> actual1 = sets[dsf.find(2)];
EXPECT(expected1 == actual1);
set<size_t> expected2; expected2 += 4,5,6;
set<size_t> actual2 = sets[dsf.find(5)];
const std::set<size_t> expected2{4, 5, 6};
std::set<size_t> actual2 = sets[dsf.find(5)];
EXPECT(expected2 == actual2);
}

Expand Down
6 changes: 1 addition & 5 deletions gtsam/base/tests/testFastContainers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@
#include <gtsam/base/FastSet.h>
#include <gtsam/base/FastVector.h>

#include <boost/assign/std/vector.hpp>
#include <boost/assign/std/set.hpp>

#include <CppUnitLite/TestHarness.h>

using namespace boost::assign;
using namespace gtsam;

/* ************************************************************************* */
Expand All @@ -25,7 +21,7 @@ TEST( testFastContainers, KeySet ) {
KeyVector init_vector {2, 3, 4, 5};

KeySet actSet(init_vector);
KeySet expSet; expSet += 2, 3, 4, 5;
KeySet expSet{2, 3, 4, 5};
EXPECT(actSet == expSet);
}

Expand Down
Loading

0 comments on commit f7c6f2b

Please sign in to comment.