changed interface for both unwhitenedError and evaluateError

release/4.3a0
kartik arcot 2023-01-04 14:34:26 -08:00
parent 97269afe4b
commit fcf339a31a
2 changed files with 32 additions and 14 deletions

View File

@ -7,8 +7,10 @@ if(NOT DEFINED CMAKE_MACOSX_RPATH)
endif()
option(GTSAM_NO_BOOST_CPP17 "Require and use boost" ON)
add_definitions(-Wno-deprecated-declarations)
if (GTSAM_NO_BOOST_CPP17)
add_definitions(-DNO_BOOST_CPP17)
set(CMAKE_CXX_STANDARD 17)
endif()
@ -57,9 +59,8 @@ endif()
include(cmake/HandleGeneralOptions.cmake) # CMake build options
# Libraries:
if (GTSAM_NO_BOOST_CPP17)
if (NOT GTSAM_NO_BOOST_CPP17)
include(cmake/HandleBoost.cmake) # Boost
add_definitions(-DNO_BOOST_CPP17)
endif()
include(cmake/HandleCCache.cmake) # ccache

View File

@ -33,7 +33,28 @@
namespace gtsam {
/* ************************************************************************* */
/*
* Some typedef based aliases to compile these interfaces without boost if
* the NO_BOOST_C17 flag is enabled
*/
#ifdef NO_BOOST_CPP17
// These typedefs and aliases will help with making the evaluateError interface
// independent of boost
#define OptionalNone nullptr
template <typename T = void>
using OptionalMatrixT = Matrix*;
using OptionalMatrix = Matrix*;
// These typedefs and aliases will help with making the unwhitenedError interface
// independent of boost
using OptionalMatrixVec = std::vector<Matrix>*;
#else
// creating a none value to use when declaring our interfaces
#define OptionalNone boost::none
template <typename T = void>
using OptionalMatrixT = boost::optional<Matrix&>;
using OptionalMatrix = boost::optional<Matrix&>;
using OptionalMatrixVec = boost::optional<std::vector<Matrix>&>;
#endif
/**
* Nonlinear factor base class
*
@ -206,7 +227,6 @@ protected:
NoiseModelFactor(const SharedNoiseModel& noiseModel) : noiseModel_(noiseModel) {}
public:
/** Print */
void print(const std::string& s = "",
const KeyFormatter& keyFormatter = DefaultKeyFormatter) const override;
@ -230,8 +250,7 @@ public:
* If the optional arguments is specified, it should compute
* both the function evaluation and its derivative(s) in H.
*/
virtual Vector unwhitenedError(const Values& x,
boost::optional<std::vector<Matrix>&> H = boost::none) const = 0;
virtual Vector unwhitenedError(const Values& x, OptionalMatrixVec H = OptionalNone) const = 0;
/**
* Vector of errors, whitened
@ -428,8 +447,6 @@ class NoiseModelFactorN
/* Like std::void_t, except produces `boost::optional<Matrix&>` instead of
* `void`. Used to expand fixed-type parameter-packs with same length as
* ValueTypes. */
template <typename T>
using OptionalMatrix = boost::optional<Matrix&>;
/* Like std::void_t, except produces `Key` instead of `void`. Used to expand
* fixed-type parameter-packs with same length as ValueTypes. */
@ -541,7 +558,7 @@ class NoiseModelFactorN
*/
Vector unwhitenedError(
const Values& x,
boost::optional<std::vector<Matrix>&> H = boost::none) const override {
OptionalMatrixVec H = OptionalNone) const override {
return unwhitenedError(boost::mp11::index_sequence_for<ValueTypes...>{}, x,
H);
}
@ -573,7 +590,7 @@ class NoiseModelFactorN
* @param[out] H The Jacobian with respect to each variable (optional).
*/
virtual Vector evaluateError(const ValueTypes&... x,
OptionalMatrix<ValueTypes>... H) const = 0;
OptionalMatrixT<ValueTypes>... H) const = 0;
/// @}
@ -587,7 +604,7 @@ class NoiseModelFactorN
* e.g. `const Vector error = factor.evaluateError(pose, point);`
*/
inline Vector evaluateError(const ValueTypes&... x) const {
return evaluateError(x..., OptionalMatrix<ValueTypes>()...);
return evaluateError(x..., OptionalMatrixT<ValueTypes>()...);
}
/** Some (but not all) optional Jacobians are omitted (function overload)
@ -599,7 +616,7 @@ class NoiseModelFactorN
inline Vector evaluateError(const ValueTypes&... x,
OptionalJacArgs&&... H) const {
return evaluateError(x..., std::forward<OptionalJacArgs>(H)...,
boost::none);
OptionalNone);
}
/// @}
@ -615,7 +632,7 @@ class NoiseModelFactorN
inline Vector unwhitenedError(
boost::mp11::index_sequence<Indices...>, //
const Values& x,
boost::optional<std::vector<Matrix>&> H = boost::none) const {
OptionalMatrixVec H = OptionalNone) const {
if (this->active(x)) {
if (H) {
return evaluateError(x.at<ValueTypes>(keys_[Indices])...,