[Cython] c-array of numpy ndarrays?
Dag Sverre Seljebotn
dagss at student.matnat.uio.no
Fri May 8 16:27:11 CEST 2009
Brian Blais wrote:
> Hello,
>
> In my question for optimization of my routines, I am trying to pre-fill
> a static c-array from a list of numpy ndarrays. Previously, I did
> something like:
>
> cdef double *w[30]
> cdef int r[30],c[30]
>
> and then I'd run through my list, and get the shape info and the data
> pointer, and fill in these arrays. This works, but then I have to do
> all my 2D -> 1D indexing, like:
>
> w[k][i+c[k]*j]
>
> which is ugly, and prone to typos. I'd like to do:
So the underlying problem here is that each array has a (widely
different) size?
> cdef np.ndarray w[30]
No, it will be a long while before you can do this. Perhaps in a year
one /might/ be able to use e.g. a C++ vector of buffers, but no promises.
You can always wrap the solution above into e.g. a cdef class, so that
you can write
yourspecialarrayobject.get(k, i, j)
--
Dag Sverre
More information about the Cython-dev
mailing list