[Cython] aritmetic with arrays in Cython

Matěj Laitl matej at laitl.cz
Fri Aug 8 11:07:27 CEST 2014


On Friday 08 of August 2014 07:05:08 Stefan Behnel wrote:
> 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.

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.

What you suggest above would be definitely possible IMO, and it could easily 
cherry-pick some work done on Ceygen, for example how memoryviews are wrapped 
as Eigen arrays: 
https://github.com/strohel/Ceygen/blob/master/ceygen/eigen_cpp.h

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.

*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)

Regards,
	Matěj


More information about the cython-devel mailing list