The following
cimport cython
@cython.boundscheck(False)
def boundtest():
cdef int r=4
cdef double l[3]
works fine. But when I try this:
cimport cython
@cython.boundscheck(False)
def boundtest():
cdef int r=4
cdef double l[r]
I receive the following error:
[1/1] Cythonizing test.pyx
Error compiling Cython file:
------------------------------------------------------------
...
cimport cython
@cython.boundscheck(False)
def boundtest():
cdef int r=4
cdef double l[r]
^
------------------------------------------------------------
test.pyx:13:20: Not allowed in a constant expression
The decorator was added due to finding this related stackexchange post and reading the Cython book by Kurt W. Smith. As far as I can tell this should work to tell Cython not to worry about out of bounds errors that may result from having a dynamic indexing variable but for some reason it does not. I have also tried changing boundscheck in the compiler options and globally to no avail.
If it weren't for the Cython documentation claiming to be up to date I would think boundscheck has been depreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…