[Python-ideas] Fast sum() for non-numbers - why so much worries?
Andrew Barnert
abarnert at yahoo.com
Thu Jul 11 18:45:51 CEST 2013
On Jul 11, 2013, at 2:07, Oscar Benjamin <oscar.j.benjamin at gmail.com> wrote:
> Numpy arrays treat += differently from + in the sense that a += b
> coerces b to the same dtype as a and then adds in place whereas a + b
> uses Python style type promotion. This behaviour is by design and it
> is useful. It is also entirely appropriate (and not pathological) that
> someone would use sum() to add numpy arrays.
I forgot about this. I was positive on the first patch (+ first, then += for the rest) mainly because it speeds up sum for numpy.
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.
Of course this could be marked as a caveat for numpy--pass a scalar or array of the right dtype for start, and you get the right answer, after all.
But if numpy is the only example of a use case for sum that's reasonable today and gets faster with the patch, I don't think the tradeoff is worth it.
Since I've already asked the proponents for such examples multiple times and gotten none beyond the ones I tried to find myself, I'm assuming they are rare or unusual, so I'm -1 now.
More information about the Python-ideas
mailing list