How to use DEF for const definition in cython

2019-07-21 21:26发布

问题:

Ultimately, I want to define a bunch of c array later in the file. Since C requires the array length to be compile time constant, my attempt as follows:

DEF SIZE = 20
DEF SIZE2 = SIZE * SIZE
DEF PERIOD_SIZE = 20
# 8000
DEF SIZE3 = PERIOD_SIZE * SIZE2
DEF SIZE_COEF = 20
# 160000
DEF SIZE4 = <long> SIZE3 * SIZE_COEF # Error

I wish to use int everywhere exept for SIZE4 because it may cause overflow in some platform. However I am not able to cast since Cython doesn't seem to support the syntax.

What is the best way to define SIZE4 apart from to write it explicitly like: DEF SIZE4 = 160000

标签: cython