我试着用scipy.weave在Python中构建一个快速的最小生成树程序。不幸的是,我发现使用scipy.weave和我发现的C++库STANN更加难以实现。以下是链接到STANN库的链接:http://sites.google.com/a/compgeom.com/stann/Python scipy.weave和STANN C++库
下面是带有我编写的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"])
到目前为止没有运气在编织工作。任何想法为什么我遇到问题?谢谢您的帮助。
干杯
不是你的问题,但你的图表有多大/多密? (我使用一个简单的纯python MST,排序+ Kruskal + unionfind;大部分时间都是这样。) – denis 2010-06-30 09:00:13
我通常处理300到30000个节点。有时更大。但是对于投影分析(3D数据),MST需要计算几次。刚刚找到一种方法来使用networkx和matplotlib.delaunay在Python中编写一个MST程序,以在大约5秒内计算50,000个源的MST。现在速度够快了。 – ebressert 2010-07-08 10:56:30