-
Notifications
You must be signed in to change notification settings - Fork 10
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
Better python printing #81
Better python printing #81
Conversation
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.
Partial review. I am confused why not just add support for functionals?
https://pybind11.readthedocs.io/en/stable/advanced/cast/functional.html
Also, you've mixed up two PRs. Please separate, or wait till I add functional support, or even better, discuss?
cmake/GtwrapUtils.cmake
Outdated
# ~~~ | ||
# destination: The concatenated master interface header file will be placed here. | ||
# inputs (optional): All the input interface header files | ||
function(combine_interface_headers |
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.
What's up with this? Not part of this PR.
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.
my bad... temporarily i've just changed the base of this PR, but if this goes through before the other PR then I'll make a new branch/PR to merge
@@ -126,6 +126,23 @@ def _wrap_method(self, method, cpp_class, prefix, suffix, method_suffix=""): | |||
|
|||
if method.name == 'print': | |||
type_list = method.args.to_cpp(self.use_boost) | |||
if len(type_list) == 2 \ | |||
and 'string' in type_list[0] \ | |||
and 'gtsam::KeyFormatter' in type_list[1]: |
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.
Why make this gtsam::KeyFormatter and not a functional?
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.
not sure I understand your question - gtsam::KeyFormatter is typedef'd to boost::function, so it is a functional? Unless that's not what a functional is...
if len(type_list) == 2 \ | ||
and 'string' in type_list[0] \ | ||
and 'gtsam::KeyFormatter' in type_list[1]: | ||
ret = '''{prefix}.def("print_", |
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.
Not a good idea. If a class defines a print()
method, this might override that (or the other way around).
Once borglab/gtsam#735 merges, this will no longer be necessary so I'm closing this PR. |
Since
gtsam::KeyFormatter
is aboost::function
and pybind11 does not doboost::functions
, some modification is needed in order to be able to use theprint_(string s, KeyFormatter)
function. Specifically, theprint_
function is altered so that the python interface accepts astd::function
and then calls the gtsamprint
with the boost version. So for example:Note:
py::scoped_ostream_redirect stream;
is so that printing occurs to python sys.stdout which just generally plays nicer with python. See pybind docsAlso, this allows functionals for the keyformatter:
outputs: