testable assertions work
parent
236c02eb52
commit
18562e97ae
|
@ -20,7 +20,7 @@
|
|||
#include <gtsam/base/Testable.h>
|
||||
#include <gtsam/global_includes.h>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <optional>
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
@ -40,15 +40,15 @@ inline bool assert_equal(const Key& expected, const Key& actual, double tol = 0.
|
|||
}
|
||||
|
||||
/**
|
||||
* Comparisons for boost.optional objects that checks whether objects exist
|
||||
* Comparisons for std.optional objects that checks whether objects exist
|
||||
* before comparing their values. First version allows for both to be
|
||||
* boost::none, but the second, with expected given rather than optional
|
||||
* std::nullopt, but the second, with expected given rather than optional
|
||||
*
|
||||
* Concept requirement: V is testable
|
||||
*/
|
||||
template<class V>
|
||||
bool assert_equal(const boost::optional<V>& expected,
|
||||
const boost::optional<V>& actual, double tol = 1e-9) {
|
||||
bool assert_equal(const std::optional<V>& expected,
|
||||
const std::optional<V>& actual, double tol = 1e-9) {
|
||||
if (!expected && actual) {
|
||||
std::cout << "expected is boost::none, while actual is not" << std::endl;
|
||||
return false;
|
||||
|
@ -63,7 +63,7 @@ bool assert_equal(const boost::optional<V>& expected,
|
|||
}
|
||||
|
||||
template<class V>
|
||||
bool assert_equal(const V& expected, const boost::optional<V>& actual, double tol = 1e-9) {
|
||||
bool assert_equal(const V& expected, const std::optional<V>& actual, double tol = 1e-9) {
|
||||
if (!actual) {
|
||||
std::cout << "actual is boost::none" << std::endl;
|
||||
return false;
|
||||
|
@ -71,14 +71,6 @@ bool assert_equal(const V& expected, const boost::optional<V>& actual, double to
|
|||
return assert_equal(expected, *actual, tol);
|
||||
}
|
||||
|
||||
template<class V>
|
||||
bool assert_equal(const V& expected, const boost::optional<const V&>& actual, double tol = 1e-9) {
|
||||
if (!actual) {
|
||||
std::cout << "actual is boost::none" << std::endl;
|
||||
return false;
|
||||
}
|
||||
return assert_equal(expected, *actual, tol);
|
||||
}
|
||||
|
||||
#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V42
|
||||
/**
|
||||
|
|
|
@ -21,13 +21,13 @@ void LinearContainerFactor::initializeLinearizationPoint(const Values& lineariza
|
|||
linearizationPoint_->insert(key, linearizationPoint.at(key));
|
||||
}
|
||||
} else {
|
||||
linearizationPoint_ = boost::none;
|
||||
linearizationPoint_ = {};
|
||||
}
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
LinearContainerFactor::LinearContainerFactor(const GaussianFactor::shared_ptr& factor,
|
||||
const boost::optional<Values>& linearizationPoint)
|
||||
const std::optional<Values>& linearizationPoint)
|
||||
: NonlinearFactor(factor->keys()), factor_(factor), linearizationPoint_(linearizationPoint) {
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtsam/nonlinear/NonlinearFactorGraph.h>
|
||||
#include <gtsam/base/std_optional_serialization.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace gtsam {
|
||||
|
||||
|
@ -27,10 +30,10 @@ class GTSAM_EXPORT LinearContainerFactor : public NonlinearFactor {
|
|||
protected:
|
||||
|
||||
GaussianFactor::shared_ptr factor_;
|
||||
boost::optional<Values> linearizationPoint_;
|
||||
std::optional<Values> linearizationPoint_;
|
||||
|
||||
/** direct copy constructor */
|
||||
LinearContainerFactor(const GaussianFactor::shared_ptr& factor, const boost::optional<Values>& linearizationPoint);
|
||||
LinearContainerFactor(const GaussianFactor::shared_ptr& factor, const std::optional<Values>& linearizationPoint);
|
||||
|
||||
// Some handy typedefs
|
||||
typedef NonlinearFactor Base;
|
||||
|
@ -80,7 +83,7 @@ public:
|
|||
size_t dim() const override;
|
||||
|
||||
/** Extract the linearization point used in recalculating error */
|
||||
const boost::optional<Values>& linearizationPoint() const { return linearizationPoint_; }
|
||||
const std::optional<Values>& linearizationPoint() const { return linearizationPoint_; }
|
||||
|
||||
/**
|
||||
* Linearize to a GaussianFactor, with method depending on the presence of a linearizationPoint
|
||||
|
@ -135,7 +138,7 @@ public:
|
|||
NonlinearFactor::shared_ptr rekey(const KeyVector& new_keys) const override;
|
||||
|
||||
/// Casting syntactic sugar
|
||||
inline bool hasLinearizationPoint() const { return linearizationPoint_.is_initialized(); }
|
||||
inline bool hasLinearizationPoint() const { return linearizationPoint_.has_value(); }
|
||||
|
||||
/**
|
||||
* Simple checks whether this is a Jacobian or Hessian factor
|
||||
|
|
Loading…
Reference in New Issue