Python 2.7 cython gsl库包装器

Python 2.7 cython gsl库包装器,python-2.7,cython,Python 2.7,Cython,我想使用gnu库中的插值函数。有人能告诉我怎么做吗?以下是我一直在尝试的 import numpy as np cdef extern from "gsl/gsl_spline.h": int gsl_spline_init(gsl_spline * spline, const double xa[], const double ya[], size_t size) def cs(gsl_spline * spline,xa = np.ndarray(double_t ,ndim=1)

我想使用gnu库中的插值函数。有人能告诉我怎么做吗?以下是我一直在尝试的

 import numpy as np
 cdef extern from "gsl/gsl_spline.h":
 int gsl_spline_init(gsl_spline * spline, const double xa[], const double ya[], size_t size)
 def cs(gsl_spline * spline,xa = np.ndarray(double_t ,ndim=1) ,ya = np.ndarray(double_t ,ndim=1) , int size):   
 s = gsl_spline_init(gsl_spline * spline, dnp.ndarray(double_t ,ndim=1) xa, np.ndarray(double_t ,ndim=1) ya, int size)
 return s
但在构建文件时,我遇到了以下错误

 def cs(gsl_spline * spline,xa = np.ndarray(double_t ,ndim=1) ,ya = np.ndarray(double_t ,ndim=1) , int size):   
s = gsl_spline_init(gsl_spline * spline, dnp.ndarray(double_t ,ndim=1) xa, np.ndarray(double_t ,ndim=1) ya, int size)                                  ^


testone.pyx:14:75: Expected ')', found 'xa'
building 'pang' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes    -fPIC -I/home/sulabh/.local/lib/python2.7/site-packages/numpy/core/include -I/home/sulabh/include/ -I/usr/include/python2.7 -c testone.c -o build/temp.linux-x86_64-2.7/testone.o
testone.c:1:2: error: #error Do not use this file, it is the result of a failed Cython compilation.
error: command 'gcc' failed with exit status 1

这里有一些问题。 我会给你一些从哪里开始的想法

首先,在函数调用中放置类型声明。 它们应该放在函数签名中。 您看到的错误是因为将类型声明放在函数调用中的语法不正确

接下来,在类型声明中使用括号来表示作为参数传递给函数的NumPy数组。 你应该使用方括号。 例如,您有
dnp.ndarray(double\t,ndim=1)
。 这应该类似于
np.ndarray[double,ndim=1]
(确切的名称取决于您如何移植ndarray类)

对于类型的更清洁声明,您可能需要考虑Cython的。