[Numpy-discussion] numexpr thoughts

Tim Hochberg tim.hochberg at cox.net
Sun Mar 5 16:51:47 CST 2006


1. David already mentioned opcodes to copy from an integer array into a 
float register. Another idea would be to have an opcode to copy from a 
strided array into a register. This would save a copy for noncontiguous 
matrices and opens up the door to doing broadcasting. I think we'd have 
to tweak the main interpreter loop a bit, but I think it's doable. 
Depending how crunched we feel for opcode space, the casting array and 
this array could overlap (OP_CAST_AND_COPY for instance).

2. Something I noticed while writing tests is that the rearangement of 
operations for 'a/const' to '(1/const)*a'  changes the results slightly 
(try const=3). I don't think I care -- I just thought I'd point it out.

3. It may simplify things to use copy_c to eliminate a bunch of the 
extra bytecodes for operating on functions of more than one argument. I 
need to check the timings on this -- I don't know how much of a speed 
hit using copy_c will cause.

4. At some point I plan to add complex operations. My original thought 
was to just duplicate the current, floating-point interpreter for 
complex numbers. However, if we have opcodes for casting, it might 
instead make sense to have one interpreter that works with both. This 
would be more efficient for mixed expressions since we wouldnt' have to 
case everything complex right away. It looks like there's enough opcode 
space, although I worry a bit whether making that main switch loop huge 
is going to slow things down. Probably not, but it's something to keep 
an eye on.

5. Same thoughts as 4., but for integer operations. Potentially the 
interpreter could work with longs, doubles and cdoubles, downcasting as 
appropriate on the way out.

It's looking like numexpr could come pretty close to evaluating most 
numpy expressions if we put enough work into it. None of the required 
changes look like they should slow down the original, simple, fast case. 
However we should keep an eye on that as we go along. It's all very 
cool; I'd like to thank David for providing such a fun toy.

-tim





More information about the Numpy-discussion mailing list