Numexpr is a python module that enables jitting some expressions for working with numpy arrays. Now, it would be cool if it allowed me to do:
ne.evaluate( """
r = y
cita = 2*pi*x/x_span
nx = CENTER_X + cos( cita ) * r
ny = CENTER_Y + sin( cita ) * r
""", local_dict={ 'x': xy_array[:,0],
'y': xy_array[:,1],
'x_span': x_span,
'y_span': y_span,
'pi': 3.141592,
'nx': nxy[:0],
'ny': nxy[:1],
'CENTER_X': ...,
'CENTER_Y': ...,
},
)
where I could re-use the calculated value of cita
to calculate both nx
and ny
. Also, because I would have to retrieve x and y once and they are one after the other in memory, I would also get less cache misses; same goes for writing of nx
and ny
. However, as far as I understand, as it stands now, this kind of code is not possible with Numexpr.
So, my questions:
Is there is a more advanced thing for python+numpy that could do this? (Some super-set of numexpr)
Or, am I wrong and this could simply be done with numpy and numexpr?
NOTE 1: I know that I could implement this little function in quite a few ways in C/C++/whatever, or that I could care less about performance and do hacks that involve numpy with or without numexpr.
NOTE 2: I know about weave, but I put it in the sack of "uncool, unmaintained solutions that would involve messing with C".