On Sun, Feb 1, 2009 at 7:33 PM, Pierre GM <pgmdevl...@gmail.com> wrote:

>
> On Feb 1, 2009, at 6:32 PM, Darren Dale wrote:
> >
> >
> > Is there an analog to __array_wrap__ for preprocessing arrays on
> > their way *into* a ufunc? For example, it would be nice if one could
> > do something like:
> >
> > numpy.sin([1,2,3]*arcseconds)
> >
> > where we have the opportunity to inspect the context, convert the
> > Quantity to units of radians, and then actually call the ufunc. Is
> > this possible, or does one have to reimplement such functions?
>
> Just an idea: look at the code for numpy.ma ufuncs (in numpy.ma.core).
> By defining a few classes for unary, binary and domained functions,
> you could probably do what you want, without having to recode all the
> functions by hand.
> Another idea would be to define some specific __mul__ or __rmul__
> rules for your units, so that the list would be transformed into a
> UnitArray...


I have pretty good implementations of the arithmetic operators, so
([1,2,3]*m)*([4,5,6]*J) already works. numpy.multiply and numpy.sqrt needed
help with array_wrap. I'll study your stuff in ma, thanks for the pointer.

Darren
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to