[Numpy-discussion] New ufuncs

Charles R Harris charlesr.harris@gmail....
Wed Nov 5 00:03:38 CST 2008

On Tue, Nov 4, 2008 at 10:37 PM, Anne Archibald

> 2008/11/5 Charles R Harris <charlesr.harris@gmail.com>:
> > Hi All,
> >
> > I'm thinking of adding some new ufuncs. Some possibilities are
> >
> > expadd(a,b) = exp(a) + exp(b) -- For numbers stored as logs:
> Surely this should be log(exp(a)+exp(b))? That would be extremely useful,
> yes.

Yes, but the common case seems to be log(sum_i(exp(a_i))), which would be
inefficient if implemented with addexp.reduce.

> > absdiff(a,b) = abs(a - b) -- Useful for forming norms
> > absmax(a,b) = max(abs(a), abs(b))
> > absadd(a,b) = abs(a) + abs(b) -- Useful for L_1 norm and inequalities?
> These I find less exciting, since they can be written easily in terms
> of existing ufuncs. (The expadd can't without an if statement unless
> you want range errors.) There is some small gain in having fewer
> temporaries, but as it stands now each ufunc lives in a byzantine nest
> of code and is hard to scrutinize.

The inner loops are very simple, take a look at the current umathmodule.
It's all the cruft up top that needs to be clarified. But I was mostly
thinking of temporaries and the speed up for small arrays of not having as
much call overhead.

> > I would really like a powadd = abs(a)**p + abs(b)**p, but I can't think
> of
> > an easy way to pass a variable p that is compatible with the way ufuncs
> work
> > without going to three variables, something that might not work with the
> > reduce functions. Along these lines I also think it is time to review
> > generalized ufuncs to see what we can do with them. Thoughts?

How about an abspower(a,p) =  abs(a)**p ? That might be more useful.

> It's worth checking what reduce does on ternary ufuncs. It's not clear
> what it *should* do.

I suppose a three variable recursion would be the most natural extension,
but probably not that useful.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20081104/c756639e/attachment-0001.html 

More information about the Numpy-discussion mailing list