Hello,
In sage we have four ways if I count correctly to make `an_element`
works in a parent:
- defining an_element directly
- defining _an_element_
- defining _an_element_impl
- defining _an_element_c_impl
The winner are the two first with roughly 40% and 80% of the
implementations in Sage sources.
$ grep -lR "def\ an_element" |wc -l
39
$ grep -lR "def\ _an_element_" |wc -l
77
$ grep -lR "def\ _an_element_impl" |wc -l
8
$ grep -lR "def\ _an_element_c_impl"|wc -l
4
In sage/structure/parent.pyx it is written on top of the definition of
an_element
class Parent:
# TODO: remove once all parents in Sage will inherit properly from
# Sets().ParentMethods.an_element
cpdef an_element(self):
but in the docstring there is no mention of deprecation or whatever but
This is used both for illustration and testing purposes. If
the set ``self`` is empty, :meth:`an_element` raises the
exception :class:`EmptySetError`.
This calls :meth:`_an_element_` (which see), and caches the
result. Parent are thus encouraged to override
:meth:`_an_element_`.
The cache is in a custom field `__an_element` whose name will be changed
in #14982 for `_cache_an_element` because in one case it has to be reset.
On the other hand in the sets category already mentioned we have
class Sets:
@cached_method
def an_element(self):
return self._an_element_()
Is there a cleaning needed? If so what should be done?
My is guess that:
- all parents should define `_an_element_`
- we should get rid of `_an_element_impl` and `_an_element_c_impl`
- make the caching in `sage.structure.parent.Parent` and
`category.sets_cat.Sets` compatible. How?
Cheers,
Vincent
--
You received this message because you are subscribed to the Google Groups
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.