I have a bunch of numpy arrays as attributes of an array of python objects, in cython, in preparation for prange processing (which requires nogil), I wanted to create a memory view that was “indirect” in the first dimension, and whose further dimensions referenced the data in the numpy arrays. So suppose, objects is a list of objects, which have vector attribute.
I want to do something like:
cdef double[ ::cython.view.indirect, ::1 ] vectors
for object in objects:
vectors[ i ] = object.vector
But how should I initialize “vectors” to make this possible? If it is possible at all? Or perhaps a memoryview is only allowed to be a memoryview of one object… in which case there is another problem — how to create an array of memoryviews dynamically?
With the below code, you would use this assignment:
where
stackoverflow_contrib.pyxis as follows: