[Cython] aritmetic with arrays in Cython

Stefan Behnel stefan_ml at behnel.de
Fri Aug 8 07:05:08 CEST 2014


Ian Henriksen schrieb am 08.08.2014 um 00:58:
> On Thu, Aug 7, 2014 at 1:58 AM, Matěj Laitl wrote:
>> you may also check out https://github.com/strohel/Ceygen if it would suit
>> your needs.

Interesting project. Thanks for sharing.


> Ideally, I'm still trying to find a way to be able to do
> something syntactically like this:
> 
> cpdef whateverfunction(double[:] a, float[:] b):
>     return a + a * b + .5
> 
> It would be ideal if that sort of thing were already a part of Cython. All
> things considered though, most of what I'm looking for seems to be there.

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.

Specifically, this could be bound to the Matrix multiplication operator
(which Cython now supports anyway) and limited to C++ compilation mode
(which Eigen requires).

http://legacy.python.org/dev/peps/pep-0465/

Stefan



More information about the cython-devel mailing list