[Numpy-discussion] On my Cython/NumPy project

Dag Sverre Seljebotn dagss@student.matnat.uio...
Sat Jun 21 01:50:27 CDT 2008

Since there's been a lot of Cython discussion lately I thought I'd speak
up and start a thread specifically for my project.

We've just recently set a clear direction for my Google Summer of Code
project for integrating NumPy in a better way with Cython. What we ended
up with is that I will over the summer add Cython support for the Python 3
buffer interface:


(We aim to support NumPy back to Python 2.3, perhaps as a special case,
but the buffer interface will guide in what way we support it.)

General feedback is welcome; in particular, I need more opinions about
what syntax people would like. We seem unable to find something that we
really like; this is the current best candidate (cdef is the way you
declare types on variables in Cython):

cdef int i = 4, j = 6
cdef np.ndarray[np.float64, 2] arr = np.zeros((10, 10), dtype=np.float64)
arr[i, j] = 1

The code above the under the hood acquires a buffer and uses it for
efficient access. arr[5], arr[5,6,7], arr[2:4,...] and in general anything
but two simple indices will be passed to Python, while arr[i, j] will be
passed to the buffer.

This is a natural first step and I'll focus on this exclusively in the

(That said, once this is in place, there are of course lots of
opportunities of doing an even better job in supporting the numerical
community with Cython: ndenumerate, more efficient buffer acquisition and
array creation, more efficient calling of NumPy/SciPy functions without
going through the Python "calling convention", etc..)

Dag Sverre

More information about the Numpy-discussion mailing list