Hello,

I'm still in my iteration challenges... I put pointers to itertools
wherever it is needed for speed (i.e. choose_nk, subset, subword) as
well as additional _fast_iterator in some combinatorial classes
(SetPartitions). But now, must of the iterator yield tuples and not
lists. The timing is better by a factor > 590 for the below example.

I think I will prepare a cleaned patch for this and submit it to Sage
trac, but you have to say to me if this is a problem that generators
(at least _fast_iterator versions of them) prefer tuples to lists.

Old versions timings

    sage: S = SetPartitions(13,[5,4,4])
    sage: x =  S.__iter__()
    sage: timeit('x.next()')
    5 loops, best of 3: 1.77 ms per loop

New versions timings

    sage: S = SetPartitions(19,[12,3,2,2])
    sage: x = S._fast_iterator()
    sage: y = S.__iter__()
    sage: timeit('x.next()')
    625 loops, best of 3: 124 µs per loop
    sage: timeit('y.next()')
    625 loops, best of 3: 710 µs per loop

And from this I get a reasonable iterator over conjugacy classes of
the symmetric group.

    sage: x=conjugacy_class_iterator([3,3,3,3])
    sage: timeit('x.next()')
    625 loops, best of 3: 3.26 µs per loop

Just as a remark, the old version of SetPartitions was not able to
give me the FIRST element of SetPartitions(19, [12,3,3,2])...

Cheers,
Vincent

PS: As the speed gain is I think enough for my purpose, I won't go
further in iteration using the C/API and I put a #+experimental on the
corresponding patch. If you are interesting in going further in this
direction...

-- 
You received this message because you are subscribed to the Google Groups 
"sage-combinat-devel" 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-combinat-devel?hl=en.

Reply via email to