2012/2/16, Vincent Delecroix <20100.delecr...@gmail.com>: > 2012/2/11, Nicolas M. Thiery <nicolas.thi...@u-psud.fr>: >> On Sat, Feb 11, 2012 at 12:05:49PM +0100, Florent Hivert wrote: >>> > Together with the language-team, we decided to implement a >>> > LazyEnumeratedSet (see my patch in the queue) which takes as input an >>> > iterable (finite or infinite) and mimic a set which contains the >>> > element of the iterable. It is very useful when we do not want to >>> > implement a specific class... What do you think of it ? >>> > >>> > On the other hand, I'm a bit disappointed as it is not possible to >>> > pickle an iterator and hence my new class does not pass the TestSuite. >>> > Any idea ? >>> >>> I think this is a good idea to have this feature for the casual user but >>> that >>> it should not be used in the code. The reason are: >>> 1 - The set will not be picklable; >>> 2 - The usage of tee is likely to leak a lot of memory; >>> 3 - For programmer, I don't think it is a big save compared to subclass >>> and >>> implementing the Cardinality and __iter__ methods. Please have a >>> look it >>> some methods couldn't be lifted in the category EnumeratedSet. >>> If you agree, as a consequence, you should add a big warning at the >>> beginning >>> of the file. >>> >>> Finally, may I suggest the alternative name EnumeratedSetFromIterator ? >> >> We discussed this with Vincent over the phone: I pointed him to the >> combinatorial_class_from_iterator decorator implemented in >> class_from_iterator.patch; he volunteered to refactor it as >> enumerated_set_from_iterator. Note that, as a decorator over an >> existing function which produces an iterator, it's picklable. >> >> I think it's reasonable to use it in code for implementing little >> functions that returns a set, the main use of which will be to iterate >> over. >> > > This is now #12518. > > Following Florent, I removed ._cardinality attribute and simplify > everything. I also add an implementation of a cache which allows the > iterator to be used only once (see sage.misc.iter_with_cache). > > I get trouble with TestSuite which only works when elements of the set > have parents. In particular it does not work in the following case > {{{ > sage: from sage.sets.set_from_iterator import EnumeratedSetFromIterator > sage: E = EnumeratedSetFromIterator(graphs, > category=InfiniteEnumeratedSets()) > sage: TestSuite(E).run() > }}} > Actually the above example leads to an infinite loop. > > I wrote an implementation of the decorator for functions (which > works!) but I'm not sure about what to do for the case of methods. Any > idea ? As soon as the decorator is ready, the ticket will need review. >
Trying to put my patch a little bit higher in the queue, I noticed the presence of the patch class_from_iterator.patch (which does not commute with mine as I basically deprecate what it did). There is no author, if there is no candidate for the ownership I will simply remove it... Vincent -- You received this message because you are subscribed to the Google Groups "sage-combinat-devel" group. To post to this group, send email to sage-combinat-devel@googlegroups.com. To unsubscribe from this group, send email to sage-combinat-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sage-combinat-devel?hl=en.