Skip to content

Commit

Permalink
Merge pull request #1640 from borglab/fixes
Browse files Browse the repository at this point in the history
Various Fixes and TODOs
  • Loading branch information
dellaert authored Oct 17, 2023
2 parents 3a1fe57 + 320ac1b commit 7f51183
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 25 deletions.
4 changes: 0 additions & 4 deletions gtsam/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ if (GTSAM_USE_EIGEN_MKL)
target_include_directories(gtsam PUBLIC ${MKL_INCLUDE_DIR})
endif()

if(GTSAM_USE_TBB)
target_include_directories(gtsam PUBLIC ${TBB_INCLUDE_DIRS})
endif()

# Add includes for source directories 'BEFORE' boost and any system include
# paths so that the compiler uses GTSAM headers in our source directory instead
# of any previously installed GTSAM headers.
Expand Down
24 changes: 16 additions & 8 deletions gtsam/discrete/DecisionTreeFactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,23 @@ namespace gtsam {
}

// create new factor, note we collect keys that are not in frontalKeys
// TODO(frank): why do we need this??? result should contain correct keys!!!
/*
Due to branch merging, the labels in `result` may be missing some keys
E.g. After branch merging, we may get a ADT like:
Leaf [2] 1.0204082
This is missing the key values used for branching.
*/
KeyVector difference, frontalKeys_(frontalKeys), keys_(keys());
// Get the difference of the frontalKeys and the factor keys using set_difference
std::sort(keys_.begin(), keys_.end());
std::sort(frontalKeys_.begin(), frontalKeys_.end());
std::set_difference(keys_.begin(), keys_.end(), frontalKeys_.begin(),
frontalKeys_.end(), back_inserter(difference));

DiscreteKeys dkeys;
for (i = 0; i < keys().size(); i++) {
Key j = keys()[i];
// TODO(frank): inefficient!
if (std::find(frontalKeys.begin(), frontalKeys.end(), j) !=
frontalKeys.end())
continue;
dkeys.push_back(DiscreteKey(j, cardinality(j)));
for (Key key : difference) {
dkeys.push_back(DiscreteKey(key, cardinality(key)));
}
return std::make_shared<DecisionTreeFactor>(dkeys, result);
}
Expand Down
8 changes: 8 additions & 0 deletions gtsam/discrete/DiscreteBayesTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,12 @@ class GTSAM_EXPORT DiscreteBayesTree
/// @}
};

/// traits
template <>
struct traits<DiscreteBayesTreeClique>
: public Testable<DiscreteBayesTreeClique> {};

template <>
struct traits<DiscreteBayesTree> : public Testable<DiscreteBayesTree> {};

} // namespace gtsam
1 change: 1 addition & 0 deletions gtsam/discrete/DiscreteKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace gtsam {

void DiscreteKeys::print(const std::string& s,
const KeyFormatter& keyFormatter) const {
std::cout << (s.empty() ? "" : s + " ") << std::endl;
for (auto&& dkey : *this) {
std::cout << DefaultKeyFormatter(dkey.first) << " " << dkey.second
<< std::endl;
Expand Down
2 changes: 1 addition & 1 deletion gtsam/discrete/tests/testDiscreteMarginals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ TEST_UNSAFE( DiscreteMarginals, truss ) {

Clique expected0(std::make_shared<DiscreteConditional>((key[0] | key[2], key[4]) = "2/1 2/1 2/1 2/1"));
Clique::shared_ptr actual0 = (*bayesTree)[0];
// EXPECT(assert_equal(expected0, *actual0)); // TODO, correct but fails
EXPECT(assert_equal(expected0, *actual0));

Clique expected1(std::make_shared<DiscreteConditional>((key[1] | key[3], key[4]) = "1/2 1/2 1/2 1/2"));
Clique::shared_ptr actual1 = (*bayesTree)[1];
Expand Down
3 changes: 1 addition & 2 deletions gtsam/geometry/CameraSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,7 @@ class CameraSet : public std::vector<CAMERA, Eigen::aligned_allocator<CAMERA>> {

// (DxD) += (DxZDim) * ( (ZDimxD) - (ZDimx3) * (3xZDim) * (ZDimxD) )
// add contribution of current factor
// TODO(gareth): Eigen doesn't let us pass the expression. Call eval() for
// now...
// Eigen doesn't let us pass the expression so we call eval()
augmentedHessian.updateDiagonalBlock(
aug_i,
((FiT *
Expand Down
2 changes: 1 addition & 1 deletion gtsam/geometry/Similarity2.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class GTSAM_EXPORT Similarity2 : public LieGroup<Similarity2, 4> {
bool operator==(const Similarity2& other) const;

/// Print with optional string
void print(const std::string& s) const;
void print(const std::string& s = "") const;

GTSAM_EXPORT friend std::ostream& operator<<(std::ostream& os,
const Similarity2& p);
Expand Down
2 changes: 1 addition & 1 deletion gtsam/geometry/Similarity3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ Similarity3 Similarity3::Align(const Point3Pairs &abPointPairs) {
return internal::align(d_abPointPairs, aRb, centroids);
}

Similarity3 Similarity3::Align(const vector<Pose3Pair> &abPosePairs) {
Similarity3 Similarity3::Align(const Pose3Pairs &abPosePairs) {
const size_t n = abPosePairs.size();
if (n < 2)
throw std::runtime_error("input should have at least 2 pairs of poses");
Expand Down
4 changes: 2 additions & 2 deletions gtsam/geometry/Similarity3.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class GTSAM_EXPORT Similarity3 : public LieGroup<Similarity3, 7> {
bool operator==(const Similarity3& other) const;

/// Print with optional string
void print(const std::string& s) const;
void print(const std::string& s = "") const;

GTSAM_EXPORT friend std::ostream& operator<<(std::ostream& os,
const Similarity3& p);
Expand Down Expand Up @@ -133,7 +133,7 @@ class GTSAM_EXPORT Similarity3 : public LieGroup<Similarity3, 7> {
* computed using the algorithm described here:
* http://www5.informatik.uni-erlangen.de/Forschung/Publikationen/2005/Zinsser05-PSR.pdf
*/
static Similarity3 Align(const std::vector<Pose3Pair>& abPosePairs);
static Similarity3 Align(const Pose3Pairs& abPosePairs);

/// @}
/// @name Lie Group
Expand Down
2 changes: 2 additions & 0 deletions gtsam/geometry/geometry.i
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,7 @@ class Similarity2 {

// Standard Interface
bool equals(const gtsam::Similarity2& sim, double tol) const;
void print(const std::string& s = "") const;
Matrix matrix() const;
gtsam::Rot2& rotation();
gtsam::Point2& translation();
Expand All @@ -1105,6 +1106,7 @@ class Similarity3 {

// Standard Interface
bool equals(const gtsam::Similarity3& sim, double tol) const;
void print(const std::string& s = "") const;
Matrix matrix() const;
gtsam::Rot3& rotation();
gtsam::Point3& translation();
Expand Down
4 changes: 4 additions & 0 deletions gtsam/hybrid/HybridBayesTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ class GTSAM_EXPORT HybridBayesTree : public BayesTree<HybridBayesTreeClique> {
};

/// traits
template <>
struct traits<HybridBayesTreeClique> : public Testable<HybridBayesTreeClique> {
};

template <>
struct traits<HybridBayesTree> : public Testable<HybridBayesTree> {};

Expand Down
3 changes: 2 additions & 1 deletion gtsam/hybrid/HybridGaussianISAM.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
namespace gtsam {

/**
* @brief
* @brief Incremental Smoothing and Mapping (ISAM) algorithm
* for hybrid factor graphs.
*
* @ingroup hybrid
*/
Expand Down
2 changes: 0 additions & 2 deletions gtsam/hybrid/HybridNonlinearFactorGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ HybridGaussianFactorGraph::shared_ptr HybridNonlinearFactorGraph::linearize(
for (auto& f : factors_) {
// First check if it is a valid factor
if (!f) {
// TODO(dellaert): why?
linearFG->push_back(GaussianFactor::shared_ptr());
continue;
}
// Check if it is a nonlinear mixture factor
Expand Down
4 changes: 2 additions & 2 deletions gtsam_unstable/partition/FindSeparator-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace gtsam { namespace partition {
* whether node j is in the left part of the graph, the right part, or the
* separator, respectively
*/
std::pair<int, sharedInts> separatorMetis(idx_t n, const sharedInts& xadj,
std::pair<idx_t, sharedInts> separatorMetis(idx_t n, const sharedInts& xadj,
const sharedInts& adjncy, const sharedInts& adjwgt, bool verbose) {

// control parameters
Expand Down Expand Up @@ -277,7 +277,7 @@ namespace gtsam { namespace partition {
//throw runtime_error("separatorPartitionByMetis:stop for debug");
}

if(result.C.size() != sepsize) {
if(result.C.size() != size_t(sepsize)) {
std::cout << "total key: " << keys.size()
<< " result(A,B,C) = " << result.A.size() << ", " << result.B.size() << ", " << result.C.size()
<< "; sepsize from Metis = " << sepsize << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion python/gtsam/tests/test_backwards_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


class TestBackwardsCompatibility(GtsamTestCase):
"""Tests for the backwards compatibility for the Python wrapper."""
"""Tests for backwards compatibility of the Python wrapper."""

def setUp(self):
"""Setup test fixtures"""
Expand Down

0 comments on commit 7f51183

Please sign in to comment.