I realized that I haven’t blogged in quite a while. So here is an update.

I’ve done quite a bit on memoryviews. Firstly, I finished Cython utility codes (this is already merged) and added a utility code loader for normal utility codes and cython utility codes. This means you can now write them in a file and automatically load them. You can now also use Tempita to make it a template.

Then I fixed memoryviews, there were still quite a lot of problems with acquisition counting and other small bugs that would make a program segfault. Then I added indexing, slicing, transposing and casting of pointers to cython.array.
You can index and slice a memoryview in GIL or nogil mode and you can coerce from slices to a Python memoryview object (which can also be indexed, sliced, transposed, etc). For transposing a memoryview slice you will need the GIL, although it’s wouldn’t be hard to drop that requirement. This all works in the
same way as NumPy (a.T gives a transposed view, you can index with Ellipsis, etc).

If you have a pointer, you can cast it by providing some shape information, like

cdef cython.array my_array = <int[:10, :10]> my_data_pointer

which will obtain a cython.array with shape 10 * 10 (so the data block must be at least of size 10 * 10 * sizeof(int)). You can then also register a callback to free the data.

Documentation is here:

In the future these slices and memoryview objects may be made more NumPy like by giving them a ‘.flat’ attribute, and a ‘.reshape’ method. We might also give them a ‘to_numpy()’ method to turn them into a numpy.ndarray.

You can now also convert a python dict to a C or Cython struct automatically (which means you can also have them as arguments in ‘def’ functions, etc).


About markflorisson

Blog for the Cython gsoc 2011
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s