I have an array of float values that is created in regular Python, that I want to pass to a cython function that fronts for an underlying C function.
The C function requires the array to be passed as a floating pointer as in:
void setOverlays(const float * verts);
the cython wrapper looks like this:
def set_overlays(verts):
setOverlays(verts)
How can I make verts into a cython array?
I thought that this might work:
cdef float * cVerts = [v for v in verts]
but unfortunately the value generated is a Python object and in this case automatic conversion does not work.
The equivalent expression(that works) in ctypes is:
cVerts = (c_float * len(verts))()
for i in range(len(verts)):
cVerts[i] = verts[i]
setOverlays(cast(byteref(cVerts), POINTER(c_float)))
I am trying to achieve the same thing, but in cython
Thanks in advance!
I found the Cython specific way:
Interestingly enough the above two solutions were rejected by the cython compiler.