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

发布于 2024-09-07 05:03:15 字数 1096 浏览 3 评论 0原文

我正在尝试 scipy.weave 在 Python 中构建一个快速的最小生成树程序。不幸的是,将 scipy.weave 与我发现的 C++ 库 STANN 一起使用比我想象的要困难。以下是 STANN 库的链接: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"])

到目前为止,编织工作还没有成功。有什么想法为什么我会遇到问题吗?感谢您的帮助。

干杯

I'm trying out scipy.weave to build a fast minimal spanning tree program in Python. Unfortunately, using scipy.weave with a C++ library that I found, STANN, is more difficult that I had assumed. Here's the link to the STANN library: http://sites.google.com/a/compgeom.com/stann/

Below is the Python with scipy.weave script that I wrote.

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"])

So far no luck in making weave work. Any ideas why I'm running into a problem? Thanks for the help.

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十雾 2024-09-14 05:03:15

用 weave 包装外部代码是一件脆弱且棘手的事情。您应该看看 Cython ——它在这类事情上非常出色。

Wrapping external code with weave is a fragile and hacky affair. You should take a look at Cython -- it's great at this sort of stuff.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文