2014-11-04 112 views
1

我想使用gnu库中的插值函数可以有人建议我,我该怎么做。这是我一直在尝试。cython-gsl库包装

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 

回答

0

这里有一些错误。 我会给你一些关于从哪里开始的想法。

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

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

对于更清晰的类型声明,您可能需要考虑Cython的typed memoryviews

+0

感谢提供的信息@Ian – 2014-11-05 15:02:53