From 42dafd9fa725a232be82f15a53e5ae0520d7bfc1 Mon Sep 17 00:00:00 2001 From: astrojhgu Date: Mon, 7 Feb 2011 18:10:20 +0000 Subject: git-svn-id: file:///home/svn/opt_utilities@172 ed2142bd-67ad-457f-ba7c-d818d4011675 --- interface/pymodel.hpp | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/interface/pymodel.hpp b/interface/pymodel.hpp index 8a55839..8165d6d 100644 --- a/interface/pymodel.hpp +++ b/interface/pymodel.hpp @@ -16,6 +16,50 @@ namespace opt_utilities { + template + boost::python::object convert_to_object(const T& x) + { + boost::python::list result; + for(size_t i=0;i + T convert_from_object(const boost::python::object& o,const T&) + { + T result(boost::python::len(o)); + for(int i=0;i::element_type>(o[i]); + } + return result; + } + + static inline double convert_from_object(const boost::python::object& o,double) + { + return boost::python::extract(o); + } + + static inline double convert_from_object(const boost::python::object& o,float) + { + return boost::python::extract(o); + } + + template class pymodel :public model @@ -100,7 +144,7 @@ namespace opt_utilities { args.append(get_element(p,i)); } - return boost::python::extract(pyfunc(x,args)); + return convert_from_object(pyfunc(convert_to_object(x),args),x); } const char* do_get_type_name()const -- cgit v1.2.2