[Cython] aritmetic with arrays in Cython

Stefan Behnel stefan_ml at behnel.de
Fri Aug 8 12:28:09 CEST 2014


Matěj Laitl schrieb am 08.08.2014 um 11:07:
> On Friday 08 of August 2014 07:05:08 Stefan Behnel wrote:
>> Eigen can apparently do these things already:
>>
>> http://eigen.tuxfamily.org/dox/TopicLazyEvaluation.html
>>
>> It might not be all that much work to integrate this with Cython to enable
>> syntax support. Or have some kind of preprocessor, but I guess that's not
>> going to be simpler than have it in Cython as an optional AST transform.
>> Basically, whenever an arithmetic expression consists of a mixture of
>> memory views and (optionally) scalars, it could be mapped to the kind of
>> code that Ceygen uses, just at an arbitrarily complex expression length.
> 
> Exactly! That was one of my ideas when I decided to create Ceygen, but I 
> resorted to take the easier route and made uglier static API because I didn't 
> (and still don't) have enough knowledge of Cython internals and Mark's "array 
> expressions" still looked like they are going to be merged.

There are a couple of points in favour of Eigen/Ceygen. It's a way simpler
approach than moving the entire vectorised code generator into Cython. And
it lets Eigen do the hard work, leaving only the interfacing part to
Cython. Basically, both tools can do what they're good at. We're always
happy that there's a C compiler cleaning up after us to which we can
delegate the low level optimisation and tuning stuff. The same would apply
to Eigen. It's a much more cythonic approach than what's implemented in the
pie-in-the-sky array expressions branch.

It requires a C++ compiler, but I think that's an acceptable dependency
these days in places where array computation performance matters. People
even accept a dependency on huge tool stacks like Numba/LLVM for the same
kind of tasks. An array expression syntax is just so much simpler than
writing dumb nested loops.


> Unfortunately, I no longer work on the project (my master's thesis) that 
> triggered work on Ceygen, and now I can invest only little maintenance work to 
> it.

I don't see me being the one to implement this, either. :)


> *However*, if such project is found worth to tacking by Cython devs, I can 
> imagine in my wild dreams that there may be a student at my former university 
> interested in doing it as their project. (this is rather optimistic statement, 
> please don't get too excited yet)

I'm sure there are many people who would benefit from this. Some of them
might even be able to provide funding, if someone wants to pick up this
idea. But past experience shows that we shouldn't count on this either.
It's definitely a nice project to tackle for someone who likes coding.

Stefan



More information about the cython-devel mailing list