我正在尝试使用scipy.weave用Python语言构建一个快速的最小生成树程序。不幸的是,在我找到的C++库STANN中使用scipy.weave比我想象的要困难得多。下面是斯坦恩图书馆的链接:http://sites.google.com/a/compgeom.com/stann/
下面是我写的带有scipy.weave的Python脚本。
import scipy.weave as weave
from scipy.weave import inline
import numpy
def gmst(points):
# computing GMST with STANN headers
assert(type(points) == type(numpy.array([])))
# now the c++ code
code = """
using namespace std;
typedef reviver::dpoint<double,2> Point;
typedef vector<Point>::size_type stype;
vector< std::pair<stype,stype> > outputmst;
PyArrayObject *py_val
gmst(points,outputmst);
return_val = outputmst;
"""
return inline(code,['points'],
headers = ["<iostream>","<gmst.hpp>","<dpoint.hpp>","<test.hpp>"],
include_dirs=["/home/tree/usr/STANN/include"])到目前为止,在使编织工作方面还没有运气。你知道为什么我会遇到问题吗?谢谢你的帮助。
干杯
发布于 2010-07-07 12:27:24
用weave包装外部代码是一件既脆弱又麻烦的事情。您应该看看Cython --它在这方面做得很好。
https://stackoverflow.com/questions/3146264
复制相似问题