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

 Replying to [comment:50 nbruin]:
 > A very rough implementation:
 > {{{
 > from sage.misc.lazy_attribute import lazy_attribute
 >
 > cdef class LazyAttribute:
 >     cdef public f
 >     cdef public str __name__
 >     def __init__(self,f):
 >         self.f=f
 >         self.__name__=f.__name__
 >     def __get__(self,instance,cls):
 >         if instance is None:
 >             return lazy_attribute(self.f)
 >         v=self.f(instance)
 >         setattr(instance,self.__name__,v)
 >         return v
 > }}}

 If I understand correctly, you optimize the case that the instance allows
 attribute assignment. But I think that won't be relevant in our use case:
 If there is attribute assignment (let's call it "case 1"), then we will
 use it during `__init__`, and hence an exiting non-data descriptor will be
 overridden.

 So, the choice of an implementation of the non-data descriptor will
 ''only'' matter if there is no attribute assignment available (let's call
 it "case 2"). And if I am not mistaken, your code will be  very slow in
 case 2, and certainly not faster than a @lazy_attribute.

 I think the questions to be addressed here are these:
 - Do we care about the case that a Homset in case 2? Currently, all
 Homsets are case 1, so, we could decide that Homset is a base class, and
 only sub-classes allow instantiation.
 - If we care about case 2: How can we be as fast as possible?

 If I understand correctly, using Cython's "property" would be faster than
 a @lazy_attribute in case 2, but it would make it impossible to use
 regular attributes in case 1, whence a massive slow-down in case 1 (which
 is not acceptable, as case 1 is the normal case).

 But can we benefit from a Cython implementation of lazy_attribute so that
 it becomes faster in case 2 but still results in a non-data descriptor
 that can be overridden by an attribute in case 1?

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