Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kartik/typedef optional references #1

Open
wants to merge 34 commits into
base: develop
Choose a base branch
from

Conversation

kartikarcot
Copy link
Owner

@kartikarcot kartikarcot commented Jan 7, 2023

Overview

This PR is part of a push to upgrade GTSAM to C++17, and remove boost dependencies from GTSAM. In this PR we want to update our factor interfaces and the factor implementations that use arguments of the type boost::optional<A&> to raw pointers of the type A*. We wish to do that because the semantics of raw pointers are the same as that of an optional to a reference. This is in accordance to google style guide’s recommendation for function input parameters, link here.

Details

Retaining evaluateError interface to accept both pointers and matrices

This was achieved by some templating and conditional compilation in NoiseModelFactorN class. A side-effect of this is that when a user inherits NoiseModelFactorN and implements it, they have to do something like this-
using Base::evaluateError; for all of the evaluateError overloads to be visible for the end user.

Replacing std::binds with lambdas

std::bind had a problem inferring which evaluateError overload to use through template deduction. I replaced it with lambdas instead.

OptionalJacobian

I have replaced boost::optional<Matrix&> in functions whose, input argument sizes are known, with OptionalJacobians. This enables us to use that function with both pointers and l-value references of matrices.

TODO

  • Need to update GeoGraphicLibs and compile some tests that were excluded.
  • Need to still replace boost::optional<Matrix&> in the following lines of code after discussing with Frank:
 gtsam/geometry/CameraSet.h
112:      boost::optional<Matrix&> E = boost::none) const {
141:      boost::optional<Matrix&> E = boost::none) const {

gtsam/base/tests/testOptionalJacobian.cpp
35:  boost::optional<Matrix&> optional(dynamic);

gtsam/slam/SmartFactorBase.h
207:      boost::optional<Matrix&> E = boost::none) const {
244:      boost::optional<Matrix&> E = boost::none) const {}

gtsam_unstable/slam/SmartStereoProjectionFactor.h
457:      boost::optional<Matrix&> E = boost::none) const override {
  • Need a review on Pose3Upright.cpp
  • Need a review on timePose2.cpp (Deleted a test which looked like a copy paste to me)

@kartikarcot kartikarcot changed the base branch from develop to verdant/remove-boost-optional January 7, 2023 01:19
@kartikarcot kartikarcot force-pushed the kartik/typedef-optional-references branch 2 times, most recently from a8d0fd2 to 138781a Compare January 11, 2023 00:21
Copy link
Collaborator

@dellaert dellaert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to submit my comments :-(

@@ -6,6 +6,8 @@ if(NOT DEFINED CMAKE_MACOSX_RPATH)
set(CMAKE_MACOSX_RPATH 0)
endif()

set(CMAKE_CXX_STANDARD 17)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not do this somewhere else for c++11?

map_(nullptr) {
dynamic->resize(Rows, Cols); // no malloc if correct size
usurp(dynamic->data());
OptionalJacobian(Eigen::MatrixXd* dynamic)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undo reformat (noise in PR)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not formatting noise. I added a check to see if dynamic is not nullptr.

boost::optional<Matrix&> H1 = boost::none,
boost::optional<Matrix&> H2 = boost::none) const
{
OptionalMatrixType H1 = OptionalNone, OptionalMatrixType H2 = OptionalNone) const {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no using Base

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an expression factor. It doesn’t inherit from noisemodelfactorN

@kartikarcot kartikarcot force-pushed the kartik/typedef-optional-references branch from c0ef53b to 0455c2e Compare January 11, 2023 19:27
@kartikarcot kartikarcot changed the base branch from verdant/remove-boost-optional to develop January 11, 2023 19:30
@kartikarcot kartikarcot changed the base branch from develop to verdant/remove-boost-optional January 12, 2023 17:47
@kartikarcot kartikarcot force-pushed the kartik/typedef-optional-references branch from 1b299f3 to f95e445 Compare January 18, 2023 23:38
@kartikarcot kartikarcot changed the base branch from verdant/remove-boost-optional to develop January 18, 2023 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants