#14214: Cythoned homsets
----------------------------------------------+-----------------------------
       Reporter:  SimonKing                   |         Owner:  tbd             
                 
           Type:  enhancement                 |        Status:  needs_work      
                 
       Priority:  major                       |     Milestone:  sage-5.10       
                 
      Component:  performance                 |    Resolution:                  
                 
       Keywords:  Hom, cython, cached method  |   Work issues:  How to store 
domain and codomain?
Report Upstream:  N/A                         |     Reviewers:                  
                 
        Authors:  Simon King                  |     Merged in:                  
                 
   Dependencies:  #14159, #12951, #13184      |      Stopgaps:                  
                 
----------------------------------------------+-----------------------------
Changes (by SimonKing):

  * work_issues:  Use property for domain and codomain => How to store
                  domain and codomain?


Comment:

 This is why I am not happy with "property":
 {{{
 sage: cython("""
 from sage.structure.parent cimport Parent
 cdef class Bla(Parent):
     property _domain:
         def __get__(self):
             try:
                 return self.__cached_methods['_domain']
             except KeyError:
                 raise AttributeError("%s instance has no attribute
 '_domain'"%type(self))
             except TypeError:
                 self.__cached_methods = {}
                 raise AttributeError("%s instance has no attribute
 '_domain'"%type(self))
         def __set__(self, value):
             try:
                 self.__cached_methods['_domain'] = value
             except TypeError:
                 self.__cached_methods = {}
                 self.__cached_methods['_domain'] = value
 """)
 ....:
 sage: class Blubb(Bla): pass
 sage: b = Bla()
 sage: c = Blubb()
 sage: b._domain = 1
 sage: c._domain = 1
 sage: c._codomain = 2
 sage: %timeit x = b._domain
 10000000 loops, best of 3: 133 ns per loop
 sage: %timeit x = c._domain
 10000000 loops, best of 3: 144 ns per loop
 sage: %timeit x = c._codomain
 10000000 loops, best of 3: 110 ns per loop
 }}}

 So, the property becomes slower on the subclass than on the base class,
 and a usual attribute on the subclass is faster than the property on the
 base class.

 I don't know if a solution to this problem is proposed in your comments
 (perhaps "cythoning lazy attributes"?).

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14214#comment:33>
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to