[Cython] N-d arrays, without a Python object

mark florisson markflorisson88 at gmail.com
Sun May 20 23:19:49 CEST 2012


On 20 May 2012 21:59, Pauli Virtanen <pav at iki.fi> wrote:
> Hi,
>
>
>        # OK, but slow
>        cdef double[:,:] a = np.zeros((10, 10), float)
>
>        # OK, fast (no Python object)
>        cdef double[10] a
>
>        # OK, but slow, makes Python calls (-> cython.view array)
>        cdef double[10*10] a_
>        cdef double[:,:] a = <double[:10,:10]>(<double*>a_)
>
>        # not allowed
>        cdef double[10,10] a
>
> Small N-d work arrays are quite often needed in numerical code, and I'm
> not aware of a way for conveniently getting them in Cython.
>
> Maybe the recently added improved memoryviews could allow for
> Python-less N-dim arrays? This may be reinveinting a certain language,
> but such a feature would find immediate practical use.
>
> --
> Pauli Virtanen
>
> _______________________________________________
> cython-devel mailing list
> cython-devel at python.org
> http://mail.python.org/mailman/listinfo/cython-devel

Hey Pauli,

Thanks for the feedback, that's actually really something I wanted as
well, along with variable sized C arrays while we're at it. We think
we can definitely make this work, probably with a syntax like 'cdef
double[:10, :10] myview' for memoryviews. I'm not sure when I'll have
the time to implement this, as I'm first going to focus on the gsoc,
so I can't promise anything for 0.17.

Cheers,

Mark


More information about the cython-devel mailing list