Numexpr can now handle broadcasting. As an example, check out this
implementation of the distance-in-a-bunch-of-dimenstions function that's
been going around. This is 80% faster than the most recent one posted on
my box and considerably easier to read.
expr = numexpr("(a - b)**2", [('a', float), ('b', float)])
def dist_numexpr(A, B):
return sqrt(sum(expr(A[:,newaxis], B[newaxis,:]), axis=2))
Now, if we just could do 'sum' inside the numexpr, I bet that this would
really scream. This is something that David has talked about adding at
various points. I just made his life a bit harder by supporting
broadcasting, but I still don't think it would be all that hard to add
reduction operations like sum and product as long as they were done at
the outermost level of the expression. That is, "sum(x*2 + 5)" should be
doable, but "5 + sum(x**2)" would likely be difficult.
Anyway, I thought that was cool, so I figured I'd share ;-)
[Bizzarely, numexpr seems to run faster on my box when compiled with
"-O1" than when compiled with "-O2" or "-O2 -funroll-all-loops". Go figure.]
-tim
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
Numpy-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/numpy-discussion