-
Notifications
You must be signed in to change notification settings - Fork 387
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
[python] Add pybind11 header. #1519
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.
Thanks @jmirabel for providing this.
I made some comments that are easy to handle.
bindings/python/pybind11.hpp
Outdated
template <typename T> | ||
struct convert_type { | ||
typedef T type; | ||
static inline auto _to(T t) { return t; } |
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.
inline is not needed here.
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.
@jmirabel
Could you also add Doxygen info?
I'll wait to see @wxmerkt proposal before addressing the requested changes.
You mean documenting functions in Doxygen format ? |
Yes, exactly. |
Apologies for the late response to this PR - this week is particularly busy and I wanted to experiment with combining the nice C++->Python caster with an implicit typecaster I've been using(*) - this would avoid having to wrap function calls. I might get to it tomorrow evening or Friday afternoon - however, please don't consider my slow response blocking. Would that be alright or would you like to move ahead before? In general, this PR is very nice and clean, particularly the re-use when going from C++ back to Python. (*) This raises the question if an implicit type_caster is even desired since it will lead to temporaries when passing objects from Python to C++. It does make it easier to deal with Pinocchio objects for people working on modules with Pybind11 though (no wrapped calls). |
Before going further, I would prefer to see what you have. Just the C++ file without the whole project is fine. I think it is enough for me to grasp what you do exactly. |
My apologies, I went quiet on this one as I didn't find time to explore this further (it's ICRA season). What I've been doing creates a The code snippet for Python-to-C++ without wrapping the functions is: #define BOOST_PYTHON_TO_PYBIND11_TYPE_CASTER(native_type, boost_python_name) \
namespace pybind11 \
{ \
namespace detail \
{ \
template <> \
struct type_caster<native_type> \
{ \
public: \
PYBIND11_TYPE_CASTER(native_type, boost_python_name); \
/* Python -> C++ */ \
bool load(handle src, bool) \
{ \
PyObject* source = src.ptr(); \
value = boost::python::extract<native_type>(source); \
return !PyErr_Occurred(); \
} \
/* C++ -> Python */ \
static handle cast(native_type src, return_value_policy policy, handle parent) \
{ \
/* TODO */ \
throw std::runtime_error("C++ to Python not yet implemented!"); \
return PyLong_FromLong(1); \
} \
}; \
} /* namespace detail */ \
} /* namespace pybind11 */
BOOST_PYTHON_TO_PYBIND11_TYPE_CASTER(pinocchio::Model, _("pinocchio.pinocchio_pywrap.Model"));
// etc |
That's neat. I'll give a try to @wxmerkt and update my PR. |
I had a look and it results in a copy in both directions. Given the definition of I think it is fine to provide both options:
|
It should be easy to implement the C++ -> Python. @wxmerkt Do you need it? |
@jmirabel Could you fix the CI issues? I would suggest using a CMake external project to find PyBind11 instead of relying on the one installed on the system. |
It's in my todo list.
You mean let CMake download the sources at configure time ? |
Yes, this is what I mean. |
The error on Windows looks unrelated to this PR:
Any hint of what's happening ? |
It is weird that this is only occurring on this test. Could you check this is not an issue of include? |
It happens from the pybind11 unit test but I don't get what I do wrong.
What do you mean ? |
I think on Windows they might me issue with comma parsing in Macros. |
The issue is with template<typename T1, typename T2> \
inline typename internal::return_type_min<T1,T2>::type min(const T1 & a, const T2 & b) \
{ return internal::call_min<T1,T2>::run(a,b); } Precisely, it isn't happy about the first |
CI is now all green except from codacy which shows what appears like irrelevant issues. |
Follows discussion #1518
I think the minimum C++ standard of my solution is 14. Not sure it works with 11.
@wxmerkt I would be happy to see your solution.