我正在尝试使用 scipy.weave.inline 将 ctype 变量传递给内联 c 代码。人们会认为这很简单。使用普通的 python 对象类型时,文档很好,但是,它们具有比我需要的更多的功能,并且在使用 C 时使用 ctypes 对我来说更有意义。但是,我不确定我的错误在哪里。
from scipy.weave import inline
from ctypes import *
def test():
y = c_float()*50
x = pointer(y)
code = """
#line 120 "laplace.py" (This is only useful for debugging)
int i;
for (i=0; i < 50; i++) {
x[i] = 1;
}
"""
inline(code, [x], compiler = 'gcc')
return y
output = test()
pi = pointer(output)
print pi[0]