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

Pauli Virtanen pav at iki.fi
Sun May 20 22:59:58 CEST 2012


	# 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

More information about the cython-devel mailing list