[Numpy-discussion] optimizing power() for complex and real cases
Travis Oliphant
oliphant.travis at ieee.org
Tue Feb 21 10:58:04 EST 2006
Tim Hochberg wrote:
> Yeah, sort of. I meant that the little helper functions that ufuncs
> call, such as DOUBLE_multiply, take the same types of arguments.
> However, I just realized that I'm not certain that's true -- I just
> assumed it because all the one's I've ever seen do. Also, this isn't
> really a problem anyway -- the real problem is the slow conversion of
> Python scalars to arrays in ufuncs.
Yes, that is true. We have only defined multiplication for same-types.
But, I just wanted to clarify that the ufunc machinery is more general
than that, because others have been confused in the past.
> I took a look at this earlier and it appears that the reason that
> conversion of Python scalars are slow is that FromAny trys every other
> conversion first. The check for Python scalars looks pretty cheap, so
> it seems reasonable to check for them and do the appropriate
> conversion early. Do the ufunc's call EnsureArray or FromAny? If the
> former it would seem pretty straighforward to just stick another check
> in there. Then David's original strategy of optimizing in DOUBLE_pow
> should be close to as fast as what I'm doing.
Yes, I suspect the biggest slow-downs are the two attribute lookups
which allow anything with __array__ or the array interface defined to be
used.
I think we could special-case Python scalars in that code.
-Travis
More information about the NumPy-Discussion
mailing list