2010/6/26 Pauli Virtanen <pav@iki.fi>
Hi,
la, 2010-06-26 kello 14:24 +0200, Francesc Alted kirjoitti: [clip]
Yeah, you need to explicitly code the support for new functions in numexpr. But another possibility, more doable, would be to code the scipy.special functions by using numexpr as a computing back-end.
Would it be possible to add generic support for user-supplied ufuncs into numexpr? This would maybe be more of a convenience feature than a speed improvement, although perhaps some speed could be gained by evaluating ufuncs per-block.
Well, I'd say that this support can be faked in numexpr easily. For example, if one want to compute a certain ufunc called, say, sincos(x) defined as sin(cos(x)) (okay, that's very simple, but it will suffice for demonstration purposes), he can express that as sincos = "sin(cos(%s))", and then use it in a more complex expression like: "%s+1*cos(%s)" % (sincos % 'x', 'y') that will be expanded as: "sin(cos(x))+1*cos(y)" Of course, this is a bit crude, but I'd say that's more than enough for allowing the evaluation of moderately complex expressions. Having said this, one can always think in setting up a wrapper for doing a similar thing more elegantly (although I'm not sure if this is worth the effort). -- Francesc Alted