[Numpy-discussion] Cython 0.10 released, more NumPy features

Dag Sverre Seljebotn dagss@student.matnat.uio...
Sun Nov 9 17:01:16 CST 2008

As the latest Cython 0.10 release has some important news for 
Cython/NumPy users, I decided to post an announcement (hope that's ok).

Download at <http://cython.org>

What's new for NumPy users:

1) Support for access to complex float buffers. Cython does not have 
native complex float syntax support [1], so this is by using structs:

cdef struct cdouble:
     np.double_t real
     np.double_t imag

def f():
     cdef np.ndarray[cdouble, ndim=2] arr = np.zeros((3,3), np.cdouble)
     arr[0,1].real = 3

2) Also support for record arrays:

cdef MyStruct:
     np.int32_t one
     np.int8_t two
     np.int8_t three

def f():
     cdef MyStruct rec
     cdef np.ndarray[MyStruct] arr = np.zeros((3,), np.dtype('i4,i1,i1'))
     rec.one, rec.two, rec.three = range(1,4)
     arr[0] = rec
     print arr[0].two # prints 2

There's some restrictions though -- in general the data buffer must be 
directly cast-able to the given struct type; there's no automatic 
endian-conversion or anything like that.

3) Support for contiguous access, which makes for quicker array access 
along the last/first dimension if you know you have contiguous data:

cdef np.ndarray[int, mode="c"] arr = ...

I am likely not going to work to add features beyond this, at least this 
time around (but there might be minor tweaks and fixes). If anybody 
would like to use this but there's still showstoppers I'm unaware of 
then please let me know.

[1] It has been discussed and native complex support would be added to 
Cython if someone found time to implement it, but I can't, unfortunately.

Dag Sverre

More information about the Numpy-discussion mailing list