danshapero/sigma-examples — pull request #1 by cswiercz (2014-11-26 20:05:39+00:00)
Title: Use typed memoryviews for Cython arrays.

Convert the "old-style" syntax for converting Numpy arrays to Cython / C arrays to use memoryviews instead. (See [Typed Memoryviews](http://docs.cython.org/src/userguide/memoryviews.html) for more information.) This cleans the code and, in some cases, can improve performance.

Update the setup script as well.

Another tool you can consider adding later is [`numpy.fromfile`](http://docs.scipy.org/doc/numpy/reference/generated/numpy.fromfile.html). Apparently it's a "highly efficient way" of reading both binary data and parsing text files.

One minor note: I'm not sure if the use of `` and `` is necessary since Cython might be able to determine the appropriate type casting itself. I avoided using list / output list comprehension, such as in

x[i], y[i] = map(np.float64, line[1:3])

because Cython might first turn the output into a Python list and *then* place the corresponding data into the Cython arrays. I know it's more verbose to split up the storage but it might be epsilon more efficient.

Finally, in regards to the setup script, I just made Cython compile the contents of `thingy.c` *into* the module itself as opposed to compiling it separately and then linking. Also, since I have nothing to test on I'm not sure if all of this is without error.