From: "Nicolas M. Thiery" <Nicolas.Thi...@u-psud.fr>
Date: Sat, 27 Oct 2012 17:37:54 +0200
Local: Sat, Oct 27 2012 11:37 am
Subject: Re: [sage-combinat-devel] Global options for elements set by their parents
Hi Andrew!
On Sat, Oct 27, 2012 at 05:43:08AM -0700, Andrew Mathas wrote:
A big +1 on exploring this long desired feature set!
> Travis has is writing a nice patch #13605 which implements global options for > partitions. Among other things, these options determine how partitions are > printed (as lists, using exponential notation, compactly, ...), whether > diagrams follow the English or French conventions, whether the default ordering > is the lexicographic or dominance etc. One caveat: setting options for a preexisting parent should *not*
OK (that just affects the outputs in my own session):
sage: Partitions().options(convention="french")
OK (I own P and can do what I want with it):
sage: P = Partitions(cmp=dominance)
Not OK (this could break e.g. Symmetric Functions):
sage: Partitions().options(cmp=dominance)
> As a result of these discussions I'd like to suggest a general
I would want to extend the framework to also allow for setting options
> framework for implementing global options for element classes which > are controlled by their parents (being a parent myself I am of > course advocating for parental control here!:). for the parent itself. Things like Partitions(3, order=...) that would change the enumeration order. > The reason for this post is to ask whether need a general options mechanism for
I like the idea of something systematic! Some issues that could come
> element classes and, if so, is anyone in favour of the approach described > below. > The main idea is that the parent inherits a generic method (see below) of the > form: > def options(self, *option, **options): > r""" > Print and set options for the element class of ``self`` > """" > .... > which is used to set and print the options for the element class. In the > element_class the options to the method ``foo`` are methods of the form > ``foo_option1``, ``foo_option2`` and so on. What the ``options`` method of the > parent does is simply set ``self.element.foo`` equal to the desired option. The > nice thing about this, is that the options do not add extra overhead to the > methods and they can be added to the element class simply by adding appropriate > methods: > def _repr__fuzzy(self): return 'I am fuzzy' > def _repr__focussed(self: return 'I am focussed' > _repr_=_repr_focussed # the default > and then you can set the option with > sage: parentClass.options(_repr_='fuzzy') > This will set _repr_ = _repr__fuzzy --- or raise a ValueError if this is not > a valid option. > As a test case, I have implemented a prototype for partitions, however, the > code is completely general. Just as importantly, it seems to work quite well. > For those who want to see the details I will upload a patch trac_13605?-- > generic_partition_options-am.patch to the queue shortly. > ... > Please let me know what you think. up though: - Element classes may be shared between different parents. One needs
- Assigning methods to the class won't work with Cython classes (as
- To support options for both the parent and the elements, we probably
- One often need to change several methods (repr/latex/...) at once,
Also a comment: the result output methods like repr is meant to be
Cheers,
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||