#20166: Implement non-recursive iterator for (weighted) integer vectors
-----------------------------+------------------------------------
   Reporter:  tscrim         |            Owner:  sage-combinat
       Type:  enhancement    |           Status:  new
   Priority:  major          |        Milestone:  sage-7.1
  Component:  combinatorics  |         Keywords:
  Merged in:                 |          Authors:  Travis Scrimshaw
  Reviewers:                 |  Report Upstream:  N/A
Work issues:                 |           Branch:
     Commit:                 |     Dependencies:
   Stopgaps:                 |
-----------------------------+------------------------------------
 By implementing a non-recursive iterator, we avoid some overhead. With
 this branch, we get the following:
 {{{
 sage: I = IntegerVectors(12,7)
 sage: %timeit list(I.__iter__())
 10 loops, best of 3: 20.8 ms per loop
 sage: I = WeightedIntegerVectors(12, [4,1,2,2])
 sage: %timeit list(I.__iter__())
 1000 loops, best of 3: 291 µs per loop
 sage: I = WeightedIntegerVectors(12, [2,1,1,2])
 sage: %timeit list(I.__iter__())
 1000 loops, best of 3: 556 µs per loop
 sage: I = WeightedIntegerVectors(17, [2,1,1,2,1,1,2])
 sage: %timeit list(I.__iter__())
 10 loops, best of 3: 56.4 ms per loop
 sage: I = WeightedIntegerVectors(26, [2,1,1,2,1,1,2])
 sage: %timeit list(I.__iter__())
 1 loop, best of 3: 443 ms per loop
 }}}
 versus the current version:
 {{{
 sage: I = IntegerVectors(12,7)
 sage: %timeit list(I.__iter__())
 10 loops, best of 3: 50.3 ms per loop
 sage: %timeit list(I.__iter__())
 The slowest run took 8.13 times longer than the fastest. This could mean
 that an intermediate result is being cached.
 1000 loops, best of 3: 301 µs per loop
 sage: I = WeightedIntegerVectors(12, [2,1,1,2])
 sage: %timeit list(I.__iter__())
 1000 loops, best of 3: 554 µs per loop
 sage: I = WeightedIntegerVectors(17, [2,1,1,2,1,1,2])
 sage: %timeit list(I.__iter__())
 10 loops, best of 3: 68.1 ms per loop
 sage: I = WeightedIntegerVectors(26, [2,1,1,2,1,1,2])
 sage: %timeit list(I.__iter__())
 1 loop , best of 3: 528 ms per loop
 }}}

--
Ticket URL: <http://trac.sagemath.org/ticket/20166>
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 https://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to