1

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".

dsign
  • 12,340
  • 6
  • 59
  • 82
  • 1
    I'm confused, are you just trying to convert from cartesian to polar coordinates? – reptilicus Feb 04 '13 at 17:03
  • I used the conversion to polar coordinates as an example. I'm just looking for a general way to do this kind of things. – dsign Feb 05 '13 at 07:28
  • Cython? It doesn't look possible with numexpr from what I can see. You could also look into calling Julia from python? Not sure what you're looking for. . . – reptilicus Feb 05 '13 at 16:09
  • Thank you @reptilicus. Your comment reinforces my opinion about numexpr not being fit for this. My concrete problem was solved using an inefficient work-around, but this question was about if there was a way of having something that would allow to implement calculations by a "dag" or local variables a-ala-numexpr, with Numpy and Python. – dsign Feb 06 '13 at 09:12

0 Answers0