[Pyrex] Initialisation of cdef global arrays with constants
sjmachin at lexicon.net
sjmachin at lexicon.net
Thu Dec 30 22:58:28 CET 2004
Hello all,
Where in Python I would have at global level:
blah_table = (0, 1, 2, 42, 255)
or in C:
static const int blah_table[5] = {0, 1, 2, 42, 255};
Pyrex appears not to support (yet?) a statement like:
cdef int blah_table[5] = {0, 1, 2, 42, 255}
N.B. I know that I can use the Python style in Pyrex but I want fast
access to the tables.
So far my best try is something like this:
cdef copy_int_py2c(int target[], object source):
cdef int x, count
count = len(source)
for x from 0 <= x < count:
target[x] = source[x]
cdef int blah1[5]
copy_int_py2c(blah1, [0,1,2,42,255])
cdef int blah2[.....
copy_....
This works for speed, at the expense of code bloat. If the tables were
large, it would be a worry.
Any better suggestions?
Thanks in advance,
John
More information about the Pyrex
mailing list