-
Notifications
You must be signed in to change notification settings - Fork 13
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
Extend ProfileDictionary in Python #59
Extend ProfileDictionary in Python #59
Conversation
The design is intentional to decouple the different modules. The current wrappers follow the C++ library exactly, and do not attempt to make things more pythonic. In particular the memory management follows the underlying rules of the C++ library and will segfault if they are not followed correctly. We are thinking about making a higher level adapter that provides a more pythonic interface, but that would be a separate module from these wrappers. |
Okay, I assumed the different I am not really sure I understand how this decouples the modules. The compiler still needs to pull in the definition of the profiles to create those functions, so on the C++ side, the modules are still coupled. If Swig exposed the
I did not attempt to make the wrapper more Pythonic, just have a user have the exact same interface and member functions as in C++. For the |
addProfiles is a template function. Templates in C++ are not generics, and the implementation is only generated when it is used. For C++, this is transparent and handled automatically by the compiler, but for SWIG it needs to be explicitly instantiated. Take a look at the Trajopt unit test. Note this import:
Because the TrajoptDefaultPlanProfile exists in the tesseract_motion_planners_trajopt module, the corresponding ProfileDictionary_addProfile_TrajOptPlanProfile also exists in that module. This implementation detail of generating the addProfile implementation for TrajoptDefaultPlanProfile would be handled transparently by the C++ compiler, but needs to be handled manually in Python with SWIG. |
Yes, that's what I tried to describe. However, by creating the Effectively a function is moved from one module to another, disconnecting it from its original "parent" class. The connection between I am not sure I understand how the import is relevant. The Thanks for the answers in any case, it did make some elements more clear to me. |
In #51 I saw a comment in the code of adding a
add_profile
function for theProfileDictionary
class.I have created a small example that could do that using the available wrapper functions and extending the
ProfileDictionary
class in Python. I assumed for this example it is possible to extend a .so library with Python code.I am curious if this approach of extending some of the wrapped classes in Python to mimic the C++ functionality is something you would consider for this repository or if you would rather update the SWIG configuration to achieve the same/similar.
The example as is would likely cause some name clash, but I assume that the C++
ProfileDictionary
could be placed in a separate namespace or be renamed in the binding to do effectively the same thing.