[Numpy-discussion] proposal on ufunc shift operators.
Wed May 28 14:34:48 CDT 2008
2008/5/28 Charles R Harris <email@example.com>:
> Hi All,
> Currently we have:
> In : ones(1,dtype=int8) << ones(1,dtype=uint8)
> Out: array(, dtype=int16)
> In : ones(1,dtype=int64) << ones(1,dtype=uint64)
> Out: array(, dtype=object)
> Note the increased size in the first case and the return of a Python long
> integer object in the second. I propose that these operators should preserve
> the type of the first argument, although this is not easy to do with the
> current ufunc setup. It is impossible to use a type of sufficient size for
> all shift values and preserving the type of the first argument is what I
> think most folks would expect.
That sounds eminently sensible to me. Of course this will complicate
explaining type rules for ufuncs. An alternative is to give it some
reasonably simple non-exceptional rule and let users specify the
output dtype if they care. Still, I think in the interest of minimal
surprise, getting rid of the conversion to an object array of longs,
at least, would be a good idea.
Do we have a cyclic-shift ufunc? That is, uint8(1)<<<8==1?
More information about the Numpy-discussion