#15056: Bind the wrapped function to the instance to which a 
`CachedMethodCaller`
is bound
-------------------------------+-------------------------
       Reporter:  SimonKing    |        Owner:
           Type:  enhancement  |       Status:  new
       Priority:  major        |    Milestone:  sage-5.12
      Component:  misc         |   Resolution:
       Keywords:               |    Merged in:
        Authors:               |    Reviewers:
Report Upstream:  N/A          |  Work issues:
         Branch:               |       Commit:
   Dependencies:  #12601       |     Stopgaps:
-------------------------------+-------------------------

Comment (by SimonKing):

 Another nice feature would be: Have cached ''unbound'' methods, that will
 then be called with an additional instance. What I mean is this:
 {{{
     sage: cython_code = ['cpdef test_meth(self,x):',
     ....: '    "some doc for a wrapped cython method"',
     ....: '    return -x',
     ....: 'from sage.all import cached_method',
     ....: 'from sage.structure.parent cimport Parent',
     ....: 'cdef class MyClass(Parent):',
     ....: '    @cached_method',
     ....: '    def direct_method(self, x):',
     ....: '        "Some doc for direct method"',
     ....: '        return 2*x',
     ....: '    wrapped_method =
 cached_method(test_meth,name="wrapped_method")']
     sage: cython(os.linesep.join(cython_code))
     sage: O = MyClass()
     sage: O.wrapped_method
     Cached version of <bound method MyClass.test_meth of <type
 '_home_simon__sage_temp_linux_sqwp_site_6921_tmp_xiI4E1_spyx_0.MyClass'>>
     sage: MyClass.wrapped_method
     Cached version of <unbound method MyClass.test_meth>
     sage: MyClass.wrapped_method(O, 3) is O.wrapped_method(3)
     True
 }}}

 I am only afraid that in the case of `CachedMethodCallerNoArgs`,
 implementing this feature might imply an inacceptable slowdown. But first
 experiments show that in the case of several arguments
 (`CachedMethodCaller`) things are fine.

--
Ticket URL: <http://trac.sagemath.org/ticket/15056#comment:1>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to