static std::string parse_python_exception();
template <class T>
-boost::python::list toPythonList(std::vector<T> vector) {
+boost::python::list toPythonList(const std::vector<T>& v) {
typename std::vector<T>::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;
}
LOG_DEBUG(TAG, ss);
}
-double PredictorWrapper::predict(int index, std::vector<double> ff)
+double PredictorWrapper::predict(int index, const std::vector<double>& 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<double>(ret);
+ LOG_DEBUG(TAG, "return: " + std::to_string(rr));
+ return rr;
}
PredictorWrapper::PredictorWrapper(const std::string& fname)