I am trying to write a function for the dyadic productin cython. The way I imagined it to work was by giving to equal-sized arrays from python into the cython file, which then multiplies the components and puts them into the matrix I created beforehand.
However, in order to create a matrix of fitting size, I need to extract the input arrays' size first, which it won't let me do and gives me "Not allowed in a constant expression" instead. I read the answer in Cython: creating an array throws "not allowed in a constant expression" which explains my mistake, but does not give a solution that works for me. What is the right way to do this?
This is how I tried to implement it:
def dyadicproduct(np.ndarray[long, ndim=1, mode="c"] x not None, np.ndarray[long, ndim=1, mode="c"] y not None):
cdef int xsize
xsize = len(x)
cdef double z[xsize][xsize]
for i in range(xsize):
z[i][i] = x[i]*y[i]
for j in range(xsize):
if j != i:
z[i][j] = x[i]*y[j]
return z