I try to rewrite a complex function form Python to Cython to speed it up massively and I encounter the following problem: while compiling my function hh_vers_vector.pyx using
cdef
in Cython is for C definitions, as the name implies. Therefore the code
cdef float v[10000]
is translated to the following C code
float v[10000];
Meaning a static float array of size 10k, defined at compile time.
This, on the other hand
cdef float v[numSamples]
Would translate to the C code
int numSamples = <..>;
float v[numSamples];
This is an attempt to compile a static array containing a variable number of elements, which is not valid C. Hence the 'constant expression error'.
Either use a python list to store the floats, or dynamically allocate C arrays via malloc/free.