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
Hello there,
I'm working on Python bindings of my C++ library (a mathematical optimization solver) and I'm stuck at a point where I create a Python callback evaluate_constraints() that takes C++ arguments, pass it to the C++ library and evaluate it with C++ arguments. The callback modifies its second parameter constraints based on its first parameter x.
Unfortunately, some copy must happen somewhere, because the C++ object constraints is not modified. I'm not sure whether I missed something totally obvious (I've stumbled upon suggestions to use py::return_value_policy::reference_internal, but to no avail) or whether it is indeed a bit tricky to address.
Hope you can crack it!
Note: the second parameter is a Vector here, but for other callbacks, it could be a C++ matrix type.
Thank you,
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
Uh oh!
There was an error while loading. Please reload this page.
-
Hello there,
I'm working on Python bindings of my C++ library (a mathematical optimization solver) and I'm stuck at a point where I create a Python callback
evaluate_constraints()
that takes C++ arguments, pass it to the C++ library and evaluate it with C++ arguments. The callback modifies its second parameterconstraints
based on its first parameterx
.Unfortunately, some copy must happen somewhere, because the C++ object
constraints
is not modified. I'm not sure whether I missed something totally obvious (I've stumbled upon suggestions to usepy::return_value_policy::reference_internal
, but to no avail) or whether it is indeed a bit tricky to address.Hope you can crack it!
Note: the second parameter is a
Vector
here, but for other callbacks, it could be a C++ matrix type.Thank you,
Charlie
Beta Was this translation helpful? Give feedback.
All reactions