Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create a static C array with Cython?

I'd like to do exactly this in Cython:

cdef int shiftIndexes[] = [1,-1, 0, 2,-1, -1, 4, 0, -1, 8, 1, -1, 16, 1, 0, 32, 1, 1, 64, 0, 1, 128, -1, 1]

I've seen a few references in fixed bug reports and old email lists that static array functionality exists in Cython, but I can't find anty examples and this particular example gives me a syntax error: Syntax error in C variable declaration

Is it possible to make static C arrays with Cython?

like image 222
Rich Avatar asked Nov 30 '11 03:11

Rich


People also ask

Can we declare array as static in C?

Since their size isn't set until runtime, variable-length arrays may not be declared at file scope or with the static keyword, nor can they be declared with an initializer list.


1 Answers

Use pointer notation instead:

cdef int *shiftIndexes = [1,-1, 0, 2,-1, -1, 4, 0, -1, 8, 1, -1, 16, 1, 0, 32, 1, 1, 64, 0, 1, 128, -1, 1]

And it will work like a charm.

like image 60
tito Avatar answered Oct 14 '22 16:10

tito