Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Python scipy.weave和STANN C++;图书馆_C++_Python_Numpy_Scipy - Fatal编程技术网

C++ Python scipy.weave和STANN C++;图书馆

C++ Python scipy.weave和STANN C++;图书馆,c++,python,numpy,scipy,C++,Python,Numpy,Scipy,我正在尝试使用scipy.weave在Python中构建一个快速的最小生成树程序。不幸的是,使用ScPi.Weave+C++的库,我发现STANN,比我想象的更困难。以下是斯坦图书馆的链接: 下面是我编写的Python with scipy.weave脚本 import scipy.weave as weave from scipy.weave import inline import numpy def gmst(points): # computing GMST with STAN

我正在尝试使用scipy.weave在Python中构建一个快速的最小生成树程序。不幸的是,使用ScPi.Weave+C++的库,我发现STANN,比我想象的更困难。以下是斯坦图书馆的链接:

下面是我编写的Python with scipy.weave脚本

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"])
导入scipy.weave作为weave
从scipy.weave导入内联
进口numpy
def gmst(点数):
#用STANN报头计算GMST
断言(类型(点)=类型(numpy.array([]))
现在的C++代码
代码=”“
使用名称空间std;
typedef恢复器::dpoint Point;
typedef向量::size_类型stype;
向量outputmst;
PyArrayObject*py_val
gmst(点、输出MST);
返回值=输出mst;
"""
返回内联(代码,['points'],
标题=[“”,“”,“”,“”,“”],
include_dirs=[“/home/tree/usr/STANN/include”])
到目前为止,织布还没有成功。知道我为什么会遇到问题吗?谢谢你的帮助


Cheers

用weave包装外部代码是一件脆弱而粗糙的事情。你应该看看——这类东西很好。

不是你的问题,而是你的图表有多大/多密集?(我使用一个简单的纯python MST,sort+Kruskal+unionfind;大部分时间都在排序中。)我通常处理300到30000个节点。有时更大。但是,为了进行投影分析(3D数据),需要多次计算MST。刚刚找到了一种用Python编写MST程序的方法,使用networkx和matplotlib.delaunay在大约5秒钟内计算50000个源的MST。现在已经够快了,我来看看Cython。谢谢你的推荐。