-
Notifications
You must be signed in to change notification settings - Fork 767
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
Wrap GNC #843
Wrap GNC #843
Conversation
|
gtsam/nonlinear/nonlinear.i
Outdated
@@ -522,6 +522,14 @@ virtual class DoglegParams : gtsam::NonlinearOptimizerParams { | |||
void setVerbosityDL(string verbosityDL) const; | |||
}; | |||
|
|||
#include <gtsam/nonlinear/GncParams.h> | |||
template<class BaseOptimizerParameters> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't be specifying templates as template<class T>
, it should be just template<T>
.
Same deal for GncOptimizer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thank you Varun
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a feeling this will compile but won't import since the templates don't have instantiations.
gtsam/nonlinear/nonlinear.i
Outdated
@@ -522,6 +522,14 @@ virtual class DoglegParams : gtsam::NonlinearOptimizerParams { | |||
void setVerbosityDL(string verbosityDL) const; | |||
}; | |||
|
|||
#include <gtsam/nonlinear/GncParams.h> | |||
template<BaseOptimizerParameters> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Use a smaller uppercase name like PARAMS
and provide either a default via the template list PARAMS = {SomeValue}
or use the typedef to declare one (I prefer the former).
Without a template list of typedef, the python module import should error out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, i checked and it compiled but import didn't work.
I updated the templates, let me know if this is what you had in mind @varunagrawal. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird, even with the updated templates we still get
======================================================================
ERROR: test_NonlinearOptimizer (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_NonlinearOptimizer
Traceback (most recent call last):
File "/usr/lib/python3.6/unittest/loader.py", line 428, in _find_test_path
module = self._get_module_from_name(name)
File "/usr/lib/python3.6/unittest/loader.py", line 369, in _get_module_from_name
__import__(name)
File "/home/runner/work/gtsam/gtsam/python/gtsam/tests/test_NonlinearOptimizer.py", line 18, in <module>
from gtsam import (DoglegOptimizer, DoglegParams,
ImportError: cannot import name 'GncParams'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing this is because we were missing GTSAM_EXPORT calls, and because the class wasn't marked as virtual in the .i files. Do we have those steps documented somewhere in gtwrap
, along with why they are required? I'm a bit confused about that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wrapper appends the template name to disambiguate between instantiations, e.g. PinholeCameraCal3_S2
vs PinholeCameraCal3Bundler
. You'll have to import the full name from gtsam import GncOptimizerGncParamsGaussNewtonParams
.
Better design would be to use
#include <gtsam/nonlinear/GncParams.h>
template<PARAMS>
virtual class GncParams {
GncParams(const PARAMS& baseOptimizerParams);
GncParams();
void print(const string& str) const;
};
typedef GncParams<gtsam::GaussNewtonParams> GncGaussNewtonParams;
typedef GncParams<gtsam::LevenbergMarquardtParams> GncLMParams;
#include <gtsam/nonlinear/GncOptimizer.h>
template<PARAMS>
virtual class GncOptimizer {
GncOptimizer(const gtsam::NonlinearFactorGraph& graph,
const gtsam::Values& initialValues,
const PARAMS& params);
gtsam::Values optimize();
};
typedef gtsam::GncOptimizer<gtsam::GncParams<gtsam::GaussNewtonParams>> GncGaussNewtonOptimizer;
typedef gtsam::GncOptimizer<gtsam::GncParams<gtsam::LevenbergMarquardtParams>> GncLMOptimizer;
You should then be able to do
from gtsam import GncLMParams, GncLMOptimizer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @varunagrawal, looks like all the tests pass now.
… names from name concat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet!
Add GNC to the wrapper.