Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a cache for .list() method in FiniteEnumeratedSet #11118

Closed
hivert opened this issue Apr 2, 2011 · 8 comments
Closed

Add a cache for .list() method in FiniteEnumeratedSet #11118

hivert opened this issue Apr 2, 2011 · 8 comments

Comments

@hivert
Copy link
Contributor

hivert commented Apr 2, 2011

There are two way to get the list of the elements of a FiniteEnumeratedSet:

     list(FSet)
     FSet.list()

The first case uses FSet.__iter__ which is slow in many practical case, for example because of deep yield recursion...

After a discussion with Nicolas, We decided the following: In the second case,
we assume that there is a need for speed and therefore we take chance to cache
the list. Here is an example of speedup (needs conbinat patches installed):

sage: %timeit list(BinaryTrees(5))
25 loops, best of 3: 24.7 ms per loop
sage: %timeit BinaryTrees(5).list()
625 loops, best of 3: 6.7 µs per loop

CC: @sagetrac-sage-combinat

Component: combinatorics

Keywords: list FiniteEnumeratedSet cache Cernay2012

Author: Florent Hivert

Reviewer: Nicolas M. Thiéry

Merged: sage-5.0.beta4

Issue created by migration from https://trac.sagemath.org/ticket/11118

@hivert
Copy link
Contributor Author

hivert commented Apr 2, 2011

comment:1

I tried the most elementary solution... It seems to work.

Please review,

Florent

@hivert
Copy link
Contributor Author

hivert commented Apr 4, 2011

comment:2

Here is an advanced solution. Please review.

@hivert

This comment has been minimized.

@hivert
Copy link
Contributor Author

hivert commented Feb 6, 2012

Changed keywords from list FiniteEnumeratedSet cache to list FiniteEnumeratedSet cache Cernay2012

@nthiery
Copy link
Contributor

nthiery commented Feb 9, 2012

comment:5

Except for a timeout in sage/sandpiles/sandpile.py, all tests passed on sage-5.0.beta2 with the following patches applied::

trac_11003-folded.patch
trac_10998-categories-posets-nt.patch
trac_10670_integral_mobius_matrix_for_posets-fh.patch
trac_11382-subposet_to_vertex_speedup-fh.patch
trac_12476-lattice_join_matrix_speedup-fh.patch
trac_11118-finite_enumset_list_cache-fh.patch

@nthiery
Copy link
Contributor

nthiery commented Feb 9, 2012

@jdemeyer
Copy link
Contributor

Reviewer: Nicolas M. Thiéry

@jdemeyer
Copy link
Contributor

Merged: sage-5.0.beta4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants