On Feb 3, 1:37 am, Nils Bruin <nbr...@sfu.ca> wrote: > See line 1807 for sage/misc/cachefunc.pyx:
Actually, I'm not so sure that code ever gets executed in our example. I certainly didn't get any results from putting "raise" or "print" commands there. On class level, there's the CachedMethod that is supposed to instantiate CachedMethodCaller to package bound methods. Line 2047 of the CachedMethod.__get__: try: name = self._cachedfunc.__name__ except AttributeError: name = self.__name__ [Caller = <some CachedMethodCaller or CachedMethodCallerNoArgs instance>] try: setattr(inst,name, Caller) return Caller <attempt to store Caller under inst.__cached_methods> return Caller so things actually go haywire earlier -- and they do for the with arguments version as well. If Foo.trac=Foo.truc is executed, it actually ISN'T a copy of the CachedMethod instance that is bound to Foo.truc. It's an unbound CachedMethodCaller (with inst=None). So it seems to me first of all class Foo: ... trac = truc and class Foo: ... Foo.trac = Foo.truc are actually NOT the same. Furthermore, in both cases, while things seem to work for methods that do take arguments, the alias is actually quite a bit slower. This is due to the fact that new instances of CachedMethodCaller keep being created and rebound, even though the lookup in the cache succeeds in that case: sage: %timeit c.truc(1) 625 loops, best of 3: 1.08 µs per loop sage: %timeit c.trac(1) 625 loops, best of 3: 2.58 µs per loop sage: Foo.tric = Foo.truc sage: %timeit c.tric(1) #varies quite a bit 625 loops, best of 3: 1.69 µs per loop so in all cases, aliasing does NOT work well with cached_method. Furthermore, I think the logic behind some of the __get__ methods might need some reconsideration. It seems that the MethodCaller.__get__ tries to replicate some of the functionality of CachedMethod.__get__ (which is really required to "bind" the cached method), but I'm not sure it should. -- 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 http://groups.google.com/group/sage-devel?hl=en. For more options, visit https://groups.google.com/groups/opt_out.