X-Git-Url: http://47.100.26.94:8080/?a=blobdiff_plain;ds=sidebyside;f=src%2FPredictorWrapper.cpp;fp=src%2FPredictorWrapper.cpp;h=2dc7eb41d52d78d23ad0cc70c4eb56f0bf3d7d18;hb=209cfd9fe0ea398b794d1d1995629a826125f035;hp=20fefc3e6326ec2737d539fd2d3dc0528ea18c10;hpb=3aa517d206c44156fe86697aeadc5f75ea212329;p=trackerpp.git diff --git a/src/PredictorWrapper.cpp b/src/PredictorWrapper.cpp index 20fefc3..2dc7eb4 100644 --- a/src/PredictorWrapper.cpp +++ b/src/PredictorWrapper.cpp @@ -18,11 +18,11 @@ const static std::string TAG = "PredictorWrapper"; static std::string parse_python_exception(); template -boost::python::list toPythonList(std::vector vector) { +boost::python::list toPythonList(const std::vector& v) { typename std::vector::iterator iter; boost::python::list list; - for (iter = vector.begin(); iter != vector.end(); ++iter) { - list.append(*iter); + for(const auto& vv : v){ + list.append(vv); } return list; } @@ -51,16 +51,19 @@ void PredictorWrapper::dump() LOG_DEBUG(TAG, ss); } -double PredictorWrapper::predict(int index, std::vector ff) +double PredictorWrapper::predict(int index, const std::vector& ff) { LOG_DEBUG(TAG, "predict"); + py::object ret; try{ - this->predict_func(index, toPythonList(ff)); + ret = this->predict_func(index, toPythonList(ff)); } catch (boost::python::error_already_set const &){ std::string perror_str = parse_python_exception(); LOG_ERROR(TAG, "Error in Python: " + perror_str) } - return 0.1; + double rr = py::extract(ret); + LOG_DEBUG(TAG, "return: " + std::to_string(rr)); + return rr; } PredictorWrapper::PredictorWrapper(const std::string& fname)