私は私のプログラムを高速化するために、次のPythonの機能を置き換えるために、C++拡張機能を記述しようとしているを使用してパスPythonのリストブーストパイソン
Pythonの関数は、以下のdef calc_dist(fea1, fea2):
#fea1 and fea2 are two lists with same length
...
のように見えます
#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);
}
をして
のようなの.soファイルに上記のCPPコードをコンパイル:は、私は次のようにC++とブーストのpythonを使用して関数を書きました
g++ calc_dist.cpp -shared -fPIC -o calc_dist.so -I /usr/include/python2.6 -lboost_python
であり、Pythonプログラムで.soを使用しようとすると、インポートはうまく動作し、モジュールが正常にインポートされたことを示します。
私は、関数にパラメータに二つのリストを渡すたびしかし、Pythonはいずれかがこの問題を解決するためにどのように私を助けることができる
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> >)
のようなエラーを与えるのだろうか?すなわち、boostを使ってC++拡張モジュールにPythonリストを渡しますか?
ありがとうございます!
利用ブースト::のpython ::リストは、この質問[参照...あなたが始めるために十分近いです](http://stackoverflow.com/questions/3761391/boostpython-python-list-to-stdvector) –