From 1786b36aaf71d845a8afe078bb6ba2d40f437dcc Mon Sep 17 00:00:00 2001 From: NAUD Maxence <maxence.naud@cea.fr> Date: Mon, 4 Sep 2023 13:59:00 +0000 Subject: [PATCH] [Fix] Type call for GenericOperator parameters --- include/aidge/utils/Any.hpp | 2 +- include/aidge/utils/CParameter.hpp | 10 +--------- python_binding/operator/pybind_GenericOperator.cpp | 6 +++--- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/include/aidge/utils/Any.hpp b/include/aidge/utils/Any.hpp index d7ff22de2..0310c38cc 100644 --- a/include/aidge/utils/Any.hpp +++ b/include/aidge/utils/Any.hpp @@ -110,7 +110,7 @@ public: template<typename T, typename VT = _Decay_if_not_any<T>, std::enable_if_t<std::is_copy_constructible<VT>::value, bool> = true> explicit _any(T&& value) : _M_manager(&Manager<VT>::manage), - _M_data(new VT{std::forward<T>(value)}) + _M_data(new VT{std::forward<T>(value)}) {} ~_any() diff --git a/include/aidge/utils/CParameter.hpp b/include/aidge/utils/CParameter.hpp index 75c2b57ac..6e8754537 100644 --- a/include/aidge/utils/CParameter.hpp +++ b/include/aidge/utils/CParameter.hpp @@ -80,7 +80,7 @@ public: std::string getParamType(std::string const &i_ParamName){ - return m_Types[i_ParamName]; + return m_Buffer[m_Params.at(i_ParamName)].type().name(); } std::vector<std::string> getParametersName(){ @@ -93,14 +93,6 @@ public: private: std::map<std::string, std::size_t> m_Params; // { Param name : offset } - ///\brief Map to check type error - /* Note : i tried this : `std::map<std::string, std::type_info const *> mTypes;` - but looks like the type_ingo object was destroyed. - I am not a hugde fan of storing a string and making string comparison. - Maybe we can use a custom enum type (or is there a standard solution ?) - */ - std::map<std::string, std::string> m_Types; - ///\brief All raw pointers to parameters values concatenated. Use custom any class compatible with C++14. std::vector<_any> m_Buffer = {}; }; diff --git a/python_binding/operator/pybind_GenericOperator.cpp b/python_binding/operator/pybind_GenericOperator.cpp index ee3ee74c1..bec59eaf2 100644 --- a/python_binding/operator/pybind_GenericOperator.cpp +++ b/python_binding/operator/pybind_GenericOperator.cpp @@ -22,7 +22,7 @@ namespace Aidge { void init_GenericOperator(py::module& m) { py::class_<GenericOperator_Op, std::shared_ptr<GenericOperator_Op>, Operator>(m, "GenericOperatorOp", py::multiple_inheritance()) - .def("get_parameter_type", &GenericOperator_Op::getParameterType) + .def("get_parameter_type", &GenericOperator_Op::getParameterType) .def("get_parameters_name", &GenericOperator_Op::getParametersName) .def("add_parameter", &GenericOperator_Op::addParameter<bool>) .def("add_parameter", &GenericOperator_Op::addParameter<int>) @@ -34,10 +34,10 @@ void init_GenericOperator(py::module& m) { .def("add_parameter", &GenericOperator_Op::addParameter<std::vector<std::string>>) .def("get_parameter", [](GenericOperator_Op& self, std::string key) -> py::object { /* - This getParameter method returns the good python type without having to have + This getParameter method returns the good python type without having to have prior knowledge of the parameter type. */ - py::object res = py::none(); + py::object res = py::none(); std::string paramType = self.getParameterType(key); if(paramType == typeid(int).name()) res = py::cast(self.getParameter<int>(key)); -- GitLab