[Python-ideas] Fast sum() for non-numbers - why so much worries?

Joshua Landau joshua at landau.ws
Fri Jul 12 01:33:27 CEST 2013


On 11 July 2013 18:19, Oscar Benjamin <oscar.j.benjamin at gmail.com> wrote:
> On 11 July 2013 17:45, Andrew Barnert <abarnert at yahoo.com> wrote:
>> You probably won't _often_ sum arrays of different dtypes... But if you do, you certainly don't want the result to have the dtype resulting from just coercing start.dtype and iter[0].dtype.
>
> It can easily happen:
>
> import numpy as np
> initial_velocity = np.array([1, 1, 1])  # Implicitly create an int array
> velocities = [initial_velocity]
> for n in range(1000):
>     velocities.append(0.9 * velocities[-1]) # Append float arrays
> final_position = delta_t * sum(velocities)
>
> With the proposed patch all 1000 arrays after the first would count as
> zero in the final result so that the answer would be (delta_t *
> array([1, 1, 1])) instead of  (delta_t * array([10.0, 10.0, 10.0]))

The points that have led to this point have pushed me from
significantly in favour to significantly against. I'm not sure what
counts as "significantly against", but without a proper deprecation
cycle, PEP and whatnot (which I'm not sure would be worth the benefits
of the change) I'm absolutely against this. We can't rush a semantic
change for code that's in popular usage.

Apologies, Sergey, but it seems I've left for the dark side.


More information about the Python-ideas mailing list