views:

229

answers:

1

I am trying to wrap a header file which has lots of functions like this

test.h

void test(int N, int* data_in, int* data_out);

so that I can use those from numpy.

Right now I have the following cython code:

test.pyx

import numpy as np
cimport numpy as np

ctypedef np.int_t itype_t

cdef extern from 'VolumeForm.h':
    void _test 'test' (int, int*, int*)

def wrap_test(np.ndarray[itype_t, ndim=2] data):
    cdef np.ndarray[dtype_t, ndim=1] out
    out = np.zeros((data.shape[0],1), dtype=np.double)
    _test(
     data.shape[0],
     <itype_t*> data.data,
     <itype_t*> out.data
    )
    return out

However, when I try to compile it I get the error:

Error converting Pyrex file to C:
(...)
Cannot assign type 'test.itype_t *' to 'int *'

How can I fix this?

+3  A: 

This issue is currently being discussed on the Cython mailing list; apparently it stems from a small bug in one of the Cython libraries:

http://codespeak.net/mailman/listinfo/cython-dev

For the moment, one potential workaround is to use NumPy arrays of dtype np.long, and then to write 'ctypedef np.long_t itype_t' instead. Then you just have to make the C code happy with long ints instead of ints.

Zak