0

I want to create a function, which creates a 2d array of cdef class

cdef PyObject* create():
    cdef PyObject* cells[2][2]
    cdef Cell cell
    for i in range(2):
        for j in range(2):
            cell = Cell(i, j)# def class Cell: ...
            cells[i][j] = <PyObject*>cell
    return cells

Error during compilation: Cannot assign type 'PyObject *[2][2]' to 'PyObject *'

What is the proper way to return the array?

d-t
  • 153
  • 1
  • 1
  • 10
  • 1
    You're attempting to use Cython to generate C code pretty directly. See https://stackoverflow.com/questions/11656532/returning-an-array-using-c to read about why the C code you're asking for is never going to work. You also have a reference counting error. If I were you I'd use either lists or 2D Numpy arrays with dtype object instead - it's a lot simpler – DavidW Aug 29 '20 at 09:44
  • 1
    See also https://stackoverflow.com/questions/33851333/cython-how-do-you-create-an-array-of-cdef-class – DavidW Aug 29 '20 at 09:45

0 Answers0