views:

346

answers:

2

I am trying to pass a ctype variable to inline c code using scipy.weave.inline. One would think this would be simple. Documentation is good when doing it with normal python object types, however, they have a lot more features than I need, and It makes more sense to me to use ctypes when working with C. I am unsure, however, where my error is.

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]
A: 

Judging from the fact that scipy.weave predates the ctypes module by a couple of years, I would be surprised if that actually works. Did you check the documentation if they can work together?

Torsten Marek
+1  A: 

scipy.weave does not know anything about ctypes. Inputs are restricted to most of the basic builtin types, numpy arrays, wxPython objects, VTK objects, and SWIG wrapped objects. You can add your own converter code, though. There is currently not much documentation on this, but you can look at the SWIG implementation as an instructive example.

Robert Kern