[Numpy-discussion] Possible to use numexpr with user made ufuncs/scipy ufuncs?
Sat Jun 26 12:17:43 CDT 2010
Sat, 26 Jun 2010 17:51:52 +0100, Francesc Alted wrote:
> 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:
> Of course, this is a bit crude, but I'd say that's more than enough for
> allowing the evaluation of moderately complex expressions.
But what if such an expression does not exist? For example, there is no
finite closed form expression for the Bessel functions in terms of
elementary functions. An accurate implementation is rather complicated,
and usually piecewise defined.
For convenience reasons, it could be useful if one could do something like
numexpr.evaluate("cos(iv(0, x))", functions=dict(iv=scipy.special.iv))
and this would be translated to numexpr bytecode that would make a Python
function call to obtain "iv(0, x)" for each block of data required,
assuming "iv" is a vectorized function. It's of course possible to
precompute the value of "iv(0, x)", but this is extra hassle and requires
More information about the NumPy-Discussion