[Numpy-discussion] What type should / return in python 3k when applied to two integer types?
Charles R Harris
Thu Aug 27 16:56:54 CDT 2009
On Thu, Aug 27, 2009 at 3:22 PM, Christopher Barker
> Robert Kern wrote:
> > On Thu, Aug 27, 2009 at 12:43, Charles R
> > Harris<firstname.lastname@example.org> wrote:
> >> In : floor_divide(x,y).dtype
> >> Out: dtype('float64')
> > Ewww. It should be an appropriate integer type. Probably whatever x*y is.
> +1 if you are working with integers, you should get integers, because
> that's probably what you want. -- they can overflow, etc. anyway, so
> buyer beware!
> In : x.dtype
> Out: dtype('int64')
> In : y.dtype
> Out: dtype('uint64')
> In : (x * y).dtype
> Out: dtype('float64')
> hmmm -- I thought we had removed this kind of silent upcasting
> (particularly int-> float), but I guess when you mix two types, numpy
> has to choose something!
> In any case, x/y should probably return the same type as x*y.
Another possibility is to cast the signed type to unsigned of the same
precisions. But then
uint64(1)//int64(-1) == 0
which may be too much of a surprise. Note that int64(x)//uint(64) always
fits in int64, so the order of the types could be significant also. However,
too possibilities for the return type is likely a complexity too far.
The cast from signed to unsigned type of the same precision is what I would
have chosen for numpy in the first place. Then again, I tend to be a bit
"odd" about some things ;)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion