4

我正在尝试使用 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]
4

1 回答 1

4

scipy.weave 对 ctypes 一无所知。输入仅限于大多数基本内置类型、numpy 数组、wxPython 对象、VTK 对象和 SWIG 包装对象。不过,您可以添加自己的转换器代码。目前没有太多关于此的文档,但您可以将SWIG 实现视为一个有启发性的示例。

于 2009-08-26T16:47:50.537 回答