You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When one creates bindings for C++ class members using PyBind11, when exactly does the member get copied over to Python? Is it when the object is referenced in Python, or when the object member is referenced?
Consider this simple example:
// C++classMyClass
{
public:
Eigen::MatrixXd bigMatrix;
}
MyClass createBigMatrix(); // implementation creates a big matrixPYBIND11_MODULE(wrapper, m)
{
py::class_<MyClass>(m, "MyClass")
.def_readonly("bigMatrix", &MyClass::bigMatrix)
;
m.def("createBigMatrix", &createBigMatrix);
}
# Pythonimportwrapperx=wrapper.createBigImage(); # <-- does MyClass::bigImage get copied from C++ to Python here?print(x.bigImage); # <-- or does it get copied here?
In other words, is it sensible to bind members that may never be referenced/used in Python? Or is it best not to because they will be copied regardless, wasting valuable compute time and memory?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
When one creates bindings for C++ class members using PyBind11, when exactly does the member get copied over to Python? Is it when the object is referenced in Python, or when the object member is referenced?
Consider this simple example:
In other words, is it sensible to bind members that may never be referenced/used in Python? Or is it best not to because they will be copied regardless, wasting valuable compute time and memory?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions