#14214: Cythoned homsets
----------------------------------------------+-----------------------------
Reporter: SimonKing | Owner: tbd
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-5.8
Component: performance | Resolution:
Keywords: Hom, cython, cached method | Work issues: Do not change
cmp too much
Report Upstream: N/A | Reviewers:
Authors: Simon King | Merged in:
Dependencies: #14159, #12951 | Stopgaps:
----------------------------------------------+-----------------------------
Comment (by SimonKing):
Replying to [comment:17 nbruin]:
> Do you have a reason to make `domain` and `codomain` cached? Their
implementation already consists of just an attribute lookup. Are you
getting a performance increase from it?
Yes. See comment:2. A cached method is much much faster than a Python
method that does nothing but return an attribute, and it is a little
faster than directly accessing the attribute in a "timeit".
Things are slightly different if you access an attribute inside of a
method. At some point, I had added a test method that accesses
self._domain a million times or calls self.domain() a million times. In
the case of HF in comment:2, the latter was faster, but in other cases (it
seems: In cases with a short mro), direct attribute access was faster.
Anyway, that's why I like to keep the cached method ''and'' self._domain
and self._codomain around.
Note, however, that one could get rid of self._domain and self._codomain.
Namely, instead of
{{{
self._domain = X
}}}
one could do
{{{
self.domain.set_cache(X)
}}}
in `Homset.__init__`, and change the cached method into
{{{
@cached_method
def domain(self):
pass
}}}
Note that keeping the _domain and _codomain attributes is actually a
cheat:
* The purpose of this ticket is to make Homset a cdef class.
* I would like to make _codomain and _domain cdef attributes, because this
would be faster than a cached method. But this would result in a layout
conflict, as stated in comment:1
* If you try to ''directly'' call `Homset` to create an instance, you
would get an error, because you can't easily assign attributes to a cdef
class. Hence, I work with the implicit assumption that all homsets are
actually instances of ''non-cdef'' classes inheriting from `Homset`.
Do you see a way to solve this problem in a clean way (i.e., with cdef
attributes)? I'd appreciate to know!
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14214#comment:18>
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.