I guess I have one more question; sorry.
Suppose we stipulate that `np.int_(9)**np.int__(10)` should
just overflow, since that appears to be the clear intent of
the (informed) user.
When a Python 3 user writes `np.arange(10)**10`,
how are we to infer the intended type of the output?
(I specify Python 3, since it has a unified treatment of integers.)
Of course:
>>> np.find_common_type([np.int32],[int])
dtype('int32')
If this were indeed an enforced numpy convention, I would
see better the point of view on the integer exponentiation
case. But how does that reconcile with:
>>> np.find_common_type([np.int8],[np.int32])
dtype('int8')
>>> (np.arange(10,dtype=np.int8)+np.int32(2**10)).dtype
dtype('int16')
And so on. If these other binary operators upcast based
on the scalar value, why wouldn't exponentiation?
I suppose the answer is: they upcast only insofar
as necessary to fit the scalar value, which I see is
a simple and enforceable rule. However, that seems the wrong
rule for exponentiation, and in fact it is not in play:
>>> (np.int8(2)**2).dtype
dtype('int32')
OK, my question to those who have argued a**2 should
produce an int32 when a is an int32: what if a is an int8?
(Obviously the overflow problem is becoming extremely pressing ...)
Thanks,
Alan
PS Where are these casting rules documented?
_______________________________________________
NumPy-Discussion mailing list
[email protected]
https://mail.scipy.org/mailman/listinfo/numpy-discussion