#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:                  
                 
----------------------------------------------+-----------------------------

Comment (by SimonKing):

 {{{
 sage: cython("""from sage.all import Sets
 from sage.structure.parent cimport Parent
 cdef class Bla(Parent):
     def __init__(self, domain, codomain):
         try:
             self._domain_ = domain
             self._codomain_ = codomain
         except AttributeError:
             if self.__cached_methods is None:
                 self.__cached_methods = {'_domain_':domain,
 '_codomain_':codomain}
             else:
                 self.__cached_methods['_domain_'] = domain
                 self.__cached_methods['_codomain_'] = codomain
         Parent.__init__(self, category= Sets())
 """)
 ....:
 sage: class Blubb(Bla): pass
 sage: b = Bla(1,2)
 sage: c = Blubb(1,2)
 sage: %timeit x = b._domain_
 1000000 loops, best of 3: 826 ns per loop
 sage: %timeit x = c._domain_
 10000000 loops, best of 3: 114 ns per loop
 }}}

 Hmmmm. If it is possible to set attributes directly, then it is faster
 than a property. But otherwise, a property is much faster than using
 `__cached_method` for attribute lookup, even if this property uses
 `__cached_method`. And the property tends to become slower on sub-classes.

 What a dilemma...

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14214#comment:37>
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