#13982: rewrite sage.combinat.combinat.unordered_tuples using
itertools.combinations_with_replacement
-------------------------------------+-------------------------------------
Reporter: nbruin | Owner: sage-combinat
Type: enhancement | Status: needs_review
Priority: minor | Milestone: sage-6.4
Component: combinatorics | Resolution:
Keywords: | Merged in:
Authors: Travis Scrimshaw | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
public/combinat/rewrite_unordered_tuples-13982|
373e5858694adf822102b2a1b9e40ce53cd776a6
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Changes (by {'newvalue': u'Travis Scrimshaw', 'oldvalue': ''}):
* status: new => needs_review
* commit: => 373e5858694adf822102b2a1b9e40ce53cd776a6
* branch: => public/combinat/rewrite_unordered_tuples-13982
* author: => Travis Scrimshaw
Comment:
In order to get the behavior to match, I had to call `sorted(set(S))` on
the base set `S` when using `itertools`. On using the output from GAP, I
had to do `map(tuple, eval(ans))` because that returned lists (or
sometimes strings). I've given the choice to the user to decide on which
algorithm. Here are some timings (with GAP already running):
{{{
sage: %timeit unordered_tuples([1,2,3],2,algorithm='itertools')
10000 loops, best of 3: 31.9 µs per loop
sage: %timeit unordered_tuples([1,2,3],2,algorithm='gap')
1000 loops, best of 3: 1.65 ms per loop
sage: %timeit eval(gap.eval( "UnorderedTuples(%s,%s)"%([1,2,3],ZZ(2)) ))
1000 loops, best of 3: 1.65 ms per loop
sage: %timeit unordered_tuples([1,2],6)
10000 loops, best of 3: 31.4 µs per loop
sage: %timeit unordered_tuples([1,2],6,algorithm='gap')
100 loops, best of 3: 2.33 ms per loop
sage: %timeit eval(gap.eval( "UnorderedTuples(%s,%s)"%([1,2],ZZ(6)) ))
100 loops, best of 3: 2.06 ms per loop
sage: %timeit unordered_tuples(range(30), 6)
1 loops, best of 3: 590 ms per loop
sage: %timeit eval(gap.eval( "UnorderedTuples(%s,%s)"%(range(30),ZZ(6)) ))
# I got bored after a minute and killed it
}}}
So even with everything, there is a major speedup. Now once this gets
replaced with libgap (#16719), we'll have to rerun timings.
----
New commits:
||[http://git.sagemath.org/sage.git/commit/?id=373e5858694adf822102b2a1b9e40ce53cd776a6
373e585]||{{{Implemented unordered_tuples using itertools.}}}||
--
Ticket URL: <http://trac.sagemath.org/ticket/13982#comment:6>
Sage <http://www.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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.