Pauli Virtanen | 20 May 2012 22:59
Picon
Picon
Favicon

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

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

mark florisson | 20 May 2012 23:19
Picon
Gravatar

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

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
(Continue reading)


Gmane