[Numpy-discussion] numpy and cython in pure python mode

Dag Sverre Seljebotn dagss@student.matnat.uio...
Wed Sep 23 07:55:31 CDT 2009

Robert Kern wrote:
> On Tue, Sep 22, 2009 at 01:33, Sebastian Haase <seb.haase@gmail.com> wrote:
>> Hi,
>> I'm not subscribed to the cython list - hoping enough people would
>> care to justify my post here:
The post might be justified, but it is a question of available knowledge 
as well. I nearly missed this post here. The Cython user list is on:


>> I know that cython's numpy is still getting better and better over
>> time, but is it already today possible to have numpy support when
>> using Cython in "pure python" mode?
>> I like the idea of being able to develop and debug code "the python
>> way" -- and then just switching on the cython-overdrive mode.
>> (Otherwise I have very good experience using C/C++ with appropriate
>> typemaps, and I don't mind the C syntax)
>> I only recently learned about the "pure python" mode on the sympy list
>> (and at the EuroScipy2009 workshop).
>> My understanding is that Cython's pure Python mode could be "played"
>> in two ways:
>> a) either not having a .pyx-file at all and putting everything into a
>> py-file (using the "import cython" stuff)
>> or b) putting only cython specific declaration in to a pyx file having
>> the same basename as the py-file next to it.
That should be a pxd file with the same basename. And I think that mode 
should work. b), that is.

Sturla's note on the memory view syntax doesn't apply as that's not in a 
released version of Cython yet, and won't be until 0.12.1 or 0.13. But 
that could be made to support Python mode a).

Finally there's been some recent discussion on cython-dev about a tool 
which can take a pyx file as input and output pure Python.
>> One more: there is no way on reload cython-modules (yet),  right ?
> Correct. There is no way to reload any extension module.
This can be worked around (in most situations that arise in practice) by 
compiling the module with a new name each time and importing things from 
it though. Sage already kind of support it (for the %attach feature 
only), and there are patches around for pyximport in Cython that's just 
lacking testing and review. Since pyximport lacks a test suite 
altogether, nobody seems to ever get around to that.

Dag Sverre

More information about the NumPy-Discussion mailing list