id,summary,reporter,owner,description,type,status,priority,milestone,component,resolution,keywords,cc,work_issues,upstream,reviewer,author,merged,dependencies,stopgaps
11115,Rewrite cached_method in Cython,SimonKing,jason,"Broadening the original description of the ticket:

The aim is to provide a Cython version of the cached_method decorator. There are three benefits:

1)
Speed (see timings in the comments)

2)
Using cached methods in Cython code.

3) Parent and element methods of categories

Let me elaborate on the last point:

In order to make full use of the parent and element methods of a category, it should be possible to define a ''cached'' method in the category, so that any object of that category inherits it ''with caching''.

Currently, it fails as follows:
{{{
sage: class MyCategory(Category):
....:     def super_categories(self):
....:         return [Objects()]
....:     class ParentMethods:
....:         @cached_method
....:         def f(self, x):
....:             return x^2
....:
sage: cython(""""""from sage.structure.parent cimport Parent
....: cdef class MyClass(Parent): pass
....: """""")
sage: O = MyClass(category=MyCategory())
sage: O.f(4)
16
sage: O.f(x) is O.f(x)
False
}}}

So, the method is inherited, but not cached.


'''Apply:'''
 1. [attachment:11115_flat.patch]
 1. [attachment:trac_11115_docfix.patch]

Note that, if you want to '''remove''' the patches after testing them, you need to do 
{{{
rm $SAGE_ROOT/devel/sage/build/sage/misc/cachefunc.*
rm $SAGE_ROOT/devel/sage/build/*/sage/misc/cachefunc.*
}}}
Otherwise, `sage -br` would not work.",enhancement,closed,major,sage-5.0,misc,fixed,category cython cache,nthiery,,N/A,"Nicolas M. Thiéry, Andrey Novoseltsev, Volker Braun",Simon King,sage-5.0.beta0,"#9138, #11900",
