#16316: cached_function and cached_method for unhashable elements
-------------------------------------+-------------------------------------
       Reporter:  saraedum           |        Owner:
           Type:  enhancement        |       Status:  needs_review
       Priority:  minor              |    Milestone:  sage-6.3
      Component:  misc               |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Julian Rueth       |    Reviewers:  Peter Bruin, Travis
Report Upstream:  N/A                |  Scrimshaw
         Branch:                     |  Work issues:
  u/tscrim/ticket/16316              |       Commit:
   Dependencies:  #16251             |  7a9a6b2a3e4a68bfd3c9d8d6556a883e1d1161e0
                                     |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by SimonKing):

 Replying to [comment:29 tscrim]:
 > Also in short, `@lazy_attribute` makes a method (with no input args)
 behave like an attribute and is only called when necessary. IIRC it's
 faster than usual python attribute access and using `@cached_method` with
 no args.

 That's not correct. At least when you have a Python class, a lazy
 attribute ''will'' be a plain python attribute after the first access.
 Indeed, a lazy attribute `L` defined for some class `C` has a `__get__`
 method, so that `L.__get__(O, C)` assigns the output value to `O.L`, for
 an instance `O` of `C`. In other words, it overrides itself by the return
 value and thus is exactly as fast as a usual python attribute, after the
 first access.

 However, if `C` is a Cython class, attribute assignment does not always
 work. Hence, in this case, `L.__get__(O,C)` will not be able to assign the
 return value to `O.L`. By consequence, the `__get__` method will be called
 upon each single access. Hence, if I see that correctly, the performance
 will be worse than calling a method.

--
Ticket URL: <http://trac.sagemath.org/ticket/16316#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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to