Indeed RecursivelyEnumeratedSet seems to be a good fit for my needs. The only problem I encountered so far is that it does not handle KeybordInterrupts nicely either: if you interrupt the computation of graded_component(n) then graded_component(m) with m<n still produce the desired input while all the remaining m raise a StopIterator. S.
* Sébastien Labbé <sla...@gmail.com> [2016-08-23 00:51:34]: > > Are you really getting benefit from storing the state (i.e., the > actual > > iterator) on the parent itself? (I see you haven't made > ClusterAlgebra > > UniqueRepresentation, so it's not an immediate bug to have it this > way) > > Perhaps it's cleaner to hand out iterator objects that are kept > track > > of in the relevant loop. That iterator would then just die > whenever the > > frames of a KeyboardInterrupt exception are discarded and the > flawed > > state wouldn't persist. > The main benefit I get from storing the iterator is that, if the > user is > careful in calling the various functions with reasonable stopping > points, the > code never has to start searching from scratch. For example > currently > Â Â sage: A = ClusterAlgebra(['A',2,1]) > Â Â sage: A.explore_to_depth(10) > Â Â sage: A.explore_to_depth(11) > effectively only traverses the tree once to depth 11. If I were not > to store > the iterator then I would be traversing the tree twice. And > unfortunately > this is expensive. > > The method graded_component does exactly what you want. See > > https://github.com/sagemath/sage/blob/master/src/sage/sets/recursively_ > enumerated_set.pyx#L607 > Â > > -- > You received this message because you are subscribed to the Google > Groups "sage-devel" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to [1]sage-devel+unsubscr...@googlegroups.com. > To post to this group, send email to [2]sage-devel@googlegroups.com. > Visit this group at [3]https://groups.google.com/group/sage-devel. > For more options, visit [4]https://groups.google.com/d/optout. > > References > > 1. mailto:sage-devel+unsubscr...@googlegroups.com > 2. mailto:sage-devel@googlegroups.com > 3. https://groups.google.com/group/sage-devel > 4. https://groups.google.com/d/optout -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.