#14214: Cythoned homsets
----------------------------------------------+-----------------------------
Reporter: SimonKing | Owner: tbd
Type: enhancement | Status: needs_work
Priority: major | Milestone: sage-5.9
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, #13184 | Stopgaps:
----------------------------------------------+-----------------------------
Comment (by SimonKing):
Replying to [comment:19 nbruin]:
> Perhaps declaring `_domain` and `_codomain` properties rather than cdef
attributes solves the problem?
> Then at least providing the storage for those is solved within the class
itself.
How?
I guess you refer to
[http://docs.cython.org/src/userguide/extension_types.html#properties this
documentation]. It seems that you still need to provide your own way to
store the property: The storage place is not provided automatically.
Hence, to provide some value in a property, you need to store the value,
e.g., in a cdef attribute or in a usual Python attribute. You'd run into
the same problems that made me suggest to use cached methods.
Properties have a getter, a setter and a deleter. These three methods
''are'' provided by cached methods: set_cache is the setter, calling it is
the getter, and clear_cache is the deleter.
So, when you suggest to use properties, then I'd say dropping the
attributes _domain and _codomain and using @cached_method instead (setting
the domain or codomain during `__init__` by means of set_cache) is more
than a temporary hack.
> You could use the store that the cached `domain` and `codomain` provide
to store and fetch the value, since the natural thing -- a `cdef`
attribute -- doesn't seem to work due to layout issues.
Right, there is the `__cached_methods` attribute. This could be used to
store that values. Would be slower than calling a cached method without
arguments, though.
> > * 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
>
> I think they ''should'' be cdef attributes because that would allow for
way faster access in cdef-type-declared cython code than `property` access
would.
>
> However, earlier experiments I've done make me hopeful that `property`
access on python level will be fully competitive with cached methods (and
even with python access of `cdef public` attributes, because I'm sure
those are implemented via `property`).
But properties still need to access the storage space. The storage space
of a `CachedMethodCallerNoArgs` is very fast, since you won't even need a
dictionary lookup (since it does ''not'' use `__cached_methods` for
storing the value, in contrast to cached methods ''with'' arguments!).
> ... but I think we need a better temporary solution than relying on
attributes that can only be instantiated on a python subclass (which
prevents us from having fully cdef Homset subclasses!)
OK. Then dropping _domain and _codomain and using @cached_methods as an
elegant substitute for properties seems the right thing to do to me.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14214#comment:22>
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.