Hi Dan, On 26 Mai, 02:14, Dan Drake <dr...@kaist.edu> wrote: > If I use @disk_cached_function, won't it just cache the *generator* > produced by squares_less_than(10), and not anything like [0, 1, 4, 9]?
Indeed: sage: @cached_function ....: def squares_less_than(n): ....: for i in range(floor(sqrt(n))): ....: yield i^2 ....: sage: L = squares_less_than(100) sage: L.next() 0 sage: L.next() 1 sage: L.next() 4 sage: L.next() 9 sage: K = squares_less_than(100) sage: K is L True sage: K.next() 16 I think that would not change with DiskCachedMethod. However, if you start a new Sage session then the generator would be loaded from disk -- if generator objects can be pickled. Can they? No! sage: I = loads(dumps(L)) --------------------------------------------------------------------------- PicklingError Traceback (most recent call last) /home/king/<ipython console> in <module>() /mnt/local/king/SAGE/sage-4.7.rc2/local/lib/python2.6/site-packages/ sage/structure/sage_object.so in sage.structure.sage_object.dumps (sage/structure/sage_object.c:8399)() PicklingError: Can't pickle <type 'generator'>: attribute lookup __builtin__.generator failed So, I think using the existing cached_* decorators won't help. Cheers, Simon -- 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.