#2737: [with patch, needs review] add balanced_sum to Sage
------------------------------+---------------------------------------------
Reporter: mhansen | Owner: somebody
Type: enhancement | Status: new
Priority: minor | Milestone: sage-4.1.1
Component: basic arithmetic | Keywords:
Reviewer: Jason Grout | Author:
Merged: |
------------------------------+---------------------------------------------
Comment(by jason):
A more drastic example:
{{{
sage: a=[[i] for i in range(10e4)]
sage: %time b=sum(a,[])
CPU times: user 209.95 s, sys: 0.57 s, total: 210.51 s
Wall time: 245.69 s
sage: a==[[i] for i in range(10e4)]
True
sage: b==range(10e4)
True
sage: %time c=balanced_sum(a, [])
CPU times: user 0.11 s, sys: 0.00 s, total: 0.11 s
Wall time: 0.12 s
sage: a==[[i] for i in range(10e4)]
True
sage: c==range(10e4)
True
}}}
However, I also uncovered a bug because the function does not copy its
arguments (it modified the lists it was using, giving an incorrect sum).
I'm posting a revised patch. This revised patch should be reviewed.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/2737#comment:7>
Sage <http://sagemath.org/>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---