-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
shared_ptr<Eigen::ArrayXd> not mapped to python #1731
Comments
Technical 'splanationI believe to use a smart pointer in In your case, though, you have a pure Design QuestionReally, though, my main question to you is: Do you really need a
If you want to just share the number-y bits, you can return struct Rawr {
ArrayXd get_value() const { return *value; } // May want a non-null check!
void write_value(ArrayXd in) { *value = in; } // Also here!
std::shared_ptr<ArrayXd> value;
};
py::class_<Rawr>(m, "Rawr")
.def_property("value", &Rawr::get_value, &Rawr::set_value); Meta: If you have a chance, can you wrap your code with backticks |
Thank you for your answer. Sorry for the backticks. I am not familiar with github. |
Ahh, makes sense! I've had to, uh, do some pretty odd things to enable the binding of Drake without changing the API, so I completely understand! Reading briefly through the StOpt Boost.Python bindings, my assumption is that you want the functional equivalent of this code? If so, I think that's easily achievable; in this case, the above code is copying the matrix data rather than aliasing it (Line 263); you can write a You can possibly alias the existing memory, but if you're not using that (which seems like not), then I'd stick with just copying the memory. Here're the TBH, though, I generally don't use the convenience macro all that much, as I like to have more fine-tuned control (read: foot-guns). This may be overly generic / hacky, but here's what I've done in our code base to handle You can use this with the Let me know if you run into any hiccups! (though I may be a bit slow to respond...) |
Thank you for you answer. |
Hi
The library permits to map Eigen:ArrayXd (or matrix) but not some smart_pointer of it.
For example, some mapping possible with boost::python doesn't seem to be possible.
For example the following code generates an error.
#include <Eigen/Dense>
#include
#include
#include
#include <pybind11/pybind11.h>
#include <pybind11/eigen.h>
#include <pybind11/stl_bind.h>
#include <pybind11/stl.h>
class toto
{
public:
toto(){}
void useSharedPtr( const std::shared_ptr< Eigen::ArrayXd > & i ) const
{ }
};
PYBIND11_MODULE(PyBindTest, m) {
pybind11::class_< toto >(m,"toto")
.def(pybind11::init<>())
.def("useSharedPtr", &toto::useSharedPtr)
;
}
Is there a workaround ?
The text was updated successfully, but these errors were encountered: