Re: Feature suggestion: sum() ought to use a compensated summation algorithm
- From: Thomas Dybdahl Ahle <lobais@xxxxxxxxx>
- Date: Sun, 04 May 2008 00:31:01 +0200
On Sat, 2008-05-03 at 21:37 +0000, Ivan Illarionov wrote:
On Sat, 03 May 2008 20:44:19 +0200, Szabolcs Horvát wrote:
Arnaud Delobelle wrote:
sum() works for any sequence of objects with an __add__ method, not
just floats! Your algorithm is specific to floats.
This occurred to me also, but then I tried
sum(['abc', 'efg'], '')
Interesting, I always thought that sum is like shortcut of
reduce(operator.add, ...), but I was mistaken.
reduce() is more forgiving:
reduce(operator.add, ['abc', 'efg'], '' ) # it works
'abcefg'
Hm, it works for lists:
sum(([1], [2]), [])
[1, 2]
However I find the seccond argument hack ugly.
Does the sum way have any performance advantages over the reduce way?
--
Best Regards,
Med Venlig Hilsen,
Thomas
.
- Follow-Ups:
- Re: Feature suggestion: sum() ought to use a compensated summation algorithm
- From: Rhamphoryncus
- Re: Feature suggestion: sum() ought to use a compensated summation algorithm
- From: Ivan Illarionov
- Re: Feature suggestion: sum() ought to use a compensated summation algorithm
- References:
- Feature suggestion: sum() ought to use a compensated summation algorithm
- From: Szabolcs Horvát
- Re: Feature suggestion: sum() ought to use a compensated summation algorithm
- From: Arnaud Delobelle
- Re: Feature suggestion: sum() ought to use a compensated summation algorithm
- From: Szabolcs Horvát
- Re: Feature suggestion: sum() ought to use a compensated summation algorithm
- From: Ivan Illarionov
- Feature suggestion: sum() ought to use a compensated summation algorithm
- Prev by Date: PIL JPEG mis-step
- Next by Date: Re: is +=1 thread safe
- Previous by thread: Re: Feature suggestion: sum() ought to use a compensated summation algorithm
- Next by thread: Re: Feature suggestion: sum() ought to use a compensated summation algorithm
- Index(es):
Relevant Pages
|