[Numpy-discussion] numpy.vectorize performance
oliphant.travis at ieee.org
Sat Jul 15 23:01:36 CDT 2006
Nick Fotopoulos wrote:
> Dear all,
> I often make use of numpy.vectorize to make programs read more like
> the physics equations I write on paper. numpy.vectorize is basically
> a wrapper for numpy.frompyfunc. Reading Travis's Scipy Book (mine is
> dated Jan 6 2005) kind of suggests to me that it returns a full-
> fledged ufunc exactly like built-in ufuncs.
> First, is this true?
Yes, it is true. But, it is a ufunc on Python object data-types. It
is calling the underlying Python function at every point in the loop.
> Second, how is the performance? i.e., are my
> functions performing approximately as fast as they could be or would
> they still gain a great deal of speed by rewriting it in C or some
> other compiled python accelerator?
Absolutely the functions could be made faster to avoid the call back
into Python at each evaluation stage. I don't think it would be too
hard to replace the function-call with something else that could be
evaluated more quickly.
But, this has not been done yet.
> As an aside, I've found the following function decorator to be
> helpful for readability, and perhaps others will enjoy it or improve
> upon it:
Thanks for the decorator. This should be put on the www.scipy.org wiki.
More information about the Numpy-discussion