【问题标题】:Using python scipy.weave inline with ctype variables?使用带有 ctype 变量的 python scipy.weave 内联?
【发布时间】:2010-11-11 09:24:13
【问题描述】:

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

【问题讨论】:

  • 从 scipy.weave 比 ctypes 模块早几年这一事实来看,如果它真的有效,我会感到惊讶。如果他们可以一起工作,你检查过文档吗?

标签: python scipy inline-code


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-19
    • 2018-02-13
    • 2016-04-27
    • 1970-01-01
    • 1970-01-01
    • 2013-08-10
    • 2016-05-03
    相关资源
    最近更新 更多