On Jun 10, 2016 05:11, "Alan Isaac" <alan.is...@gmail.com> wrote:
>
> On 6/10/2016 2:42 AM, Nathaniel Smith wrote:
>>
>> I dunno, with my user hat on I'd be incredibly surprised / confused /
>> annoyed if an innocent-looking expression like
>>
>>   np.arange(10) ** 2
>>
>> started returning floats... having exact ints is a really nice feature
>> of Python/numpy as compared to R/Javascript, and while it's true that
>> int64 can overflow, there are also large powers that can be more
>> precisely represented as int64 than float.
>
>
>
> Is np.arange(10)**10 also "innocent looking" to a Python user?

You keep pounding on this example. It's a fine example, but, c'mon. **2 is
probably at least 100x more common in real source code. Maybe 1000x more
common. Why should we break the common case for your edge case?

> Also, I am confused by what "large powers" means in this context.
> Is 2**40 a "large power"?

I meant the range 2**53 -- 2**63 where integers have more precision than
floats. It's not a terribly important point, but it is true that there are
currently ** operations that return exact results, and that would become
impossible to do exactly if we switch ** to return floats.

> Finally, is np.arange(1,3)**-2 "innocent looking" to a Python user?

Maybe, maybe not. Historically your example here has always silently
returned nonsense, and no one seems to complain. Maybe this just means
everyone's become used to the pain, I dunno. But probably it also has
something to do with how uncommon this code is in practice. OTOH I'm
convinced that making **2 return floats is going to generate a ton of
complaints -- first because of all the code we broke, but then (I predict,
could be wrong) on an ongoing basis, as new users trip over the unexpected
**2 behavior. Because, again, **2 is something that orders of magnitude
more people will actually trip over, and in contexts where they'll have no
idea why it would return float.

(Remember that whole discussion we had at the beginning of the thread,
where very experienced numpy users started out thinking we should return
float for negative powers only, and then we had to carefully think through
how numpy's type system works to convince ourselves that this wasn't
possible? I don't really want to force every new user to recapitulate that
discussion just when they're learning what types even are...)

-n
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to