KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to write a c++ extension to replace the following python function in order to speed up my program The python function looks like the following def calc_dist(fea1, fea2): #fea1 and fea2 are two lists with same length ... I wrote the function using c++ and boost python like follows: #include <vector> #include <boost/python.hpp> double calc_dist(vector<double>& fea1, vector<double>& fea2) { int len = fea1.size(); double s=0; for(int i=0; i<len;i++){ double p=fea1[i]; double q=fea2[i]; ...//calculating.. } return s; } BOOST_PYTHON_MODULE(calc_dist) { using namespace boost::python; def("calc_dist",calc_dist); } and compile the above cpp code into a .so file like g++ calc_dist.cpp -shared -fPIC -o calc_dist.so -I /usr/include/python2.6 -lboost_python and trying to use the .so in a python program, the import works fine, indicating the module can successfully imported. However, whenever I pass two lists to the parameter to the function, python will give errors like ArgumentError: Python argument types in calc_dist.calc_dist(list, list) did not match C++ signature: calc_dist.calc_dist(std::vector<float, std::allocator<float> >, std::vector<float, std::allocator<float> >) can any one help me how to solve this problem? i.e pass a python list to c++ extension using boost? Thanks a lot!
Tags (comma-separated)
Save Edits
Cancel