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
I'm pretty familiar with how Pybind11 works. But I have a funny situation: I have a simple C++ struct for a Rational type and various functions that return it:
class Rational {
int n;
int d;
};
Rational my_function();
Rather than using py::class_<Rational> to define a new class, is it possible to get Pybind11 to bind Rational to a Python fraction? Do I have to use a custom type caster?
I want to then bind my_function as m.def("my_function", &my_function) and have it automatically return a py::object that is an instance of fraction.
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
-
I'm pretty familiar with how Pybind11 works. But I have a funny situation: I have a simple C++ struct for a Rational type and various functions that return it:
Rather than using
py::class_<Rational>
to define a new class, is it possible to get Pybind11 to bindRational
to a Python fraction? Do I have to use a custom type caster?I want to then bind
my_function
asm.def("my_function", &my_function)
and have it automatically return apy::object
that is an instance offraction
.Beta Was this translation helpful? Give feedback.
All reactions