【发布时间】:2010-12-21 00:51:31
【问题描述】:
我有一小部分现有的 C 代码想要使用 Cython 进行包装。我希望能够设置许多 numpy 数组,然后将这些数组作为参数传递给 C 代码,其函数采用标准 c 数组(1d 和 2d)。我在弄清楚如何编写正确的 .pyx 代码来正确处理事情方面有点卡住了。
有一些函数,但文件 funcs.h 中的一个典型函数看起来像:
double InnerProduct(double *A, double **coords1, double **coords2, const int len)
然后我有一个 .pyx 文件,它有一个对应的行:
cdef extern from "funcs.h":
double InnerProduct(double *A, double **coords1, double **coords2, int len)
我摆脱了 const 因为 cython 不支持它。我被卡住的地方是包装器代码应该看起来像将 MxN numpy 数组传递给 **coords1 和 **coords2 参数。
我一直在努力为此类问题找到正确的文档或教程。任何建议将不胜感激。
【问题讨论】:
-
我有一个Cython post,您或许可以提供见解。