I need to allocate memory for a large buffer, without actually initializing it (it will be used as a result buffer later and every location will be written to, so initialization is just a waste of time).
I can easily do this in Cython using:
cdef char *buff = <char *> malloc(n * sizeof(char))
if not buff :
raise MemoryError()
The problem is I'm not sure how to return this as an ndarray to python (similar to numpy array). The documentation shows how to convert this to a list and return it, but not as an array.https://cython.readthedocs.io/en/latest/src/tutorial/memory_allocation.html
return [x for x in my_array[:number]]
Returning a list isn't very useful as I want this to be interpreted as a boolean array (this buffer will be used as a mask to filter out elements).
# Index and coefficient array are both numpy ND-arrays
index_array = index_array[mask]
coeff_array = coeff_array[mask]
how can I return the buffer as a boolean array after I calculated a mask?