I would like to create a 2D-array within a cdef
function with the number of elements in each dimension depending on parameters passed to the function. E.g.:
cdef int[:,:] c_volumecheck(int n):
cdef:
const int comb = 2**n
const int nt = n
int match[comb][nt]
size_t i,j
# initialize values
for i in range(comb):
for j in range(n):
match[i][j] = 0
return match
However, assigning to comb
and nt
a constant expression does not seem to work as I get the error "Not allowed in a constant expression" in line int match[comb][nt]
. Manually providing the respective values work (match[8][3]
for e.g. n=3
). That is not an option however, as these values change during the program.
The second thing is, that I do not seem to understand how to return this array to another cdef
or def
function in the same .pyx
-script: int[:,:]
does not seem to correspond to a 2d-array like the one I want to initialize.