Skip to content
Snippets Groups Projects
Commit 6ea52b46 authored by Olivier BICHLER's avatar Olivier BICHLER
Browse files

Better handling of py::objects

parent b9ef536c
No related branches found
No related tags found
2 merge requests!212Version 0.3.0,!186Refactor OperatorImpl for backend/export
Pipeline #55187 canceled
...@@ -127,7 +127,18 @@ public: ...@@ -127,7 +127,18 @@ public:
{ {
mAnyCompare.emplace(std::make_pair<std::type_index, bool(*)(const future_std::any&, const future_std::any&)>(typeid(T), mAnyCompare.emplace(std::make_pair<std::type_index, bool(*)(const future_std::any&, const future_std::any&)>(typeid(T),
[](const future_std::any& lhs, const future_std::any& rhs) { [](const future_std::any& lhs, const future_std::any& rhs) {
return (future_std::any_cast<T>(lhs) < future_std::any_cast<T>(rhs)); #ifdef PYBIND
if (lhs.type() == typeid(py::object)) {
return (future_std::any_cast<py::object>(lhs).cast<T>() < future_std::any_cast<T>(rhs));
}
else if (rhs.type() == typeid(py::object)) {
return (future_std::any_cast<T>(lhs) < future_std::any_cast<py::object>(rhs).cast<T>());
}
else
#endif
{
return (future_std::any_cast<T>(lhs) < future_std::any_cast<T>(rhs));
}
})); }));
const auto dot = name.find('.'); const auto dot = name.find('.');
......
...@@ -14,7 +14,18 @@ ...@@ -14,7 +14,18 @@
std::map<std::type_index, bool(*)(const future_std::any&, const future_std::any&)> Aidge::DynamicAttributes::mAnyCompare; std::map<std::type_index, bool(*)(const future_std::any&, const future_std::any&)> Aidge::DynamicAttributes::mAnyCompare;
bool future_std::operator<(const future_std::any& lhs, const future_std::any& rhs) { bool future_std::operator<(const future_std::any& lhs, const future_std::any& rhs) {
return (lhs.type() == rhs.type()) if (lhs.type() == rhs.type()) {
? Aidge::DynamicAttributes::mAnyCompare.at(lhs.type())(lhs, rhs) return Aidge::DynamicAttributes::mAnyCompare.at(lhs.type())(lhs, rhs);
: (lhs.type().before(rhs.type())); }
#ifdef PYBIND
else if (lhs.type() == typeid(py::object)) {
return Aidge::DynamicAttributes::mAnyCompare.at(rhs.type())(lhs, rhs);
}
else if (rhs.type() == typeid(py::object)) {
return Aidge::DynamicAttributes::mAnyCompare.at(rhs.type())(lhs, rhs);
}
#endif
else {
return (lhs.type().before(rhs.type()));
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment