[Numpy-discussion] Request for clarification from Travis
Charles R Harris
Thu Jun 26 11:43:34 CDT 2008
On Thu, Jun 26, 2008 at 1:50 AM, Travis E. Oliphant <email@example.com>
> > Yes, but it is directed at the interpreter, which will raise a
> > TypeError if needed. But the interpreter doesn't know that some
> > generic function might return NotImplemented and wouldn't know what to
> > do if it did. What the user should see when they call something like
> > right_shift(a,b) and it fails is an exception, they shouldn't have to
> > check the return value
> Yes, you are right. So, the questions is how to handle this correctly.
> > I think what you want is that subtypes of ndarray can override some
> > ufuncs so that, for instance, right_shift() should interpret itself as
> > a call to arg2.__rrshift__ if it exists, even if it isn't called
> > through the interpreter friendly slot function >>. Is that correct? If
> > so, I would rather have an explicit overload flag in the subtype so
> > that the ufunc can easily do the right thing.
> So, how would this overload flag work and how would a subtype set it?
> Would this be a per-instance flag in the FLAGS field?
It's been a few days, but my last thoughts were that ufunc_generic _call,
or one of the other gateways, should play the role that the interpreter does
for NotImplemented. How exactly it determines that some function is
overridden I'm not sure. Subtypes could, for instance, have a method with
the ufunc name, but we need to be sure we don't end up in an endless loop.
> > I can't find __array_priority__ in your book, what exactly does it imply?
> The subtype with the largest priority wins in any decision about which
> subtype to create during operations involving more than one subtype
> (like adding a matrix to an array --- what should be returned?).
So it has a numeric value?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion