#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 nbruin):
Ping!. The present patches here pass doctests on the bot!
I think conceptually what you want in this case is really just a nondata
descriptor that acts as a backstopper to provide (essentially) a read-only
attribute stored in `__cached_methods` if no instance dictionary is
available (or more accurately: if it isn't used) The code at [comment:40]
provides that.
{{{
cdef class CachedAttributeType(object):
cdef public str name
def __init__(self, name):
self.name = name
def __get__(self,instance,cls):
cdef dict CM
try:
CM = getattr(instance,"__cached_methods")
return CM[self.name]
except TypeError, KeyError:
raise AttributeError("%s instance has no attribute
'%s'"%(cls,self.name))
}}}
Since the `__get__` here is very close the one of the faster code paths in
a properly cythonized `lazy_attribute` (see #14615), defining the backed
attribute either way:
{{{
_domain=CachedAttributeType("_domain")
@lazy_attribute
def _codomain(self);
raise AttributeError("You should have set me already!")
}}}
is going to give the same performance. You may be able to shave off a few
nanoseconds by replacing some of the auto-generated cython code with
explicit Python C-API calls. I suspect we'll have to live with many
parents not having a `__dict__` for the foreseeable future.
(note that any slowdowns due to deeper MRO will go away once the cython
upgrade is in).
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14214#comment:54>
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.