-
-
Notifications
You must be signed in to change notification settings - Fork 628
Lazy species #38544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Lazy species #38544
Conversation
Documentation preview for this PR (built with commit ebddbd4; changes) is ready! 🎉 |
No, you understood me correctly, I just changed my mind with what might be the best practice. (I"m not 100% convinced yet either though.) Sorry for the confusion. So what I am thinking is your original idea is best with one small modification (from this comment): def __init__(self,...):
if self._arity == 1:
from types import MethodType
self.Sets = MethodType(SetSpecies, LazySpeciesUnivariate)
self.Graphs = MethodType(GraphSpecies, LazySpeciesUnivariate)
self.SetPartitions = MethodType(SetPartitionSpecies, LazySpeciesUnivariate)
self.Cycles = MethodType(CycleSpecies, LazySpeciesUnivariate) This way it isn't a class LazySpeciesUnivariate(LazySpecies):
"""
Univariate lazy species.
"""
from types import MethodType
LazySpeciesUnivariate.Sets = MethodType(SetSpecies, LazySpeciesUnivariate)
LazySpeciesUnivariate.Graphs = MethodType(GraphSpecies, LazySpeciesUnivariate)
LazySpeciesUnivariate.SetPartitions = MethodType(SetPartitionSpecies, LazySpeciesUnivariate)
LazySpeciesUnivariate.Cycles = MethodType(CycleSpecies, LazySpeciesUnivariate) (Python doesn't seem to have a good mechanism in Python for converting classes into methods like how I am doing.) |
Indeed, it seems that
Oh yes. The code is def _repr_(self):
...
try:
s = [sorted(x) for x in self]
except TypeError:
s = [sorted(x, key=str) for x in self]
return '{' + ', '.join('{' + repr(x)[1:-1] + '}' for x in s) + '}' and it's a certain M. Rubey who is to blame. #38974. Embarassing. |
I think the problem is that, for the set partition |
I tried the second variant, but it actually doesn't work the way I did it. Apparently, However, it seems to me that the current approach (i.e., separate classes for univariate and multivariate species and providing proper methods defined in the class) makes sense. I think that we really want to see the methods ( |
Ping? |
Ah, right, it would pass the class rather than the instance. I think I messed up my initial experiment. However, this does work: sage: class Foo():
....: def __init__(self, B):
....: print(B)
sage: class Bar():
....: def __init__(self, v):
....: self.v = v
....: from types import MethodType
....: self.F = MethodType(Foo, self)
....: def __repr__(self):
....: return "Bar: %s" % self.v
sage: B = Bar(5)
sage: B.F()
Bar: 5
<__main__.Foo object at 0x723f4645e660>
Yes, that is the downside with my |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One doc thing and one general question (that I probably should have asked much earlier, sorry).
Should we call these Lazy(Combinatorial)Species
and not just (Combinatorial)Species
? Having Lazy
in front suggests there is or will be a finite precision/non-lazy version, but I don't think this will happen.
Once addressed, it will be a positive review.
@@ -407,3 +407,4 @@ Comprehensive Module List | |||
sage/combinat/words/words | |||
sage/combinat/yang_baxter_graph | |||
sage/rings/cfinite_sequence | |||
sage/rings/lazy_species |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably should put this with the L's rather than at the bottom. Also, would there be some other natural place to link this doc? It's hard to find just being in the big combinat module list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean, move it between k_tableau
and lr_tableau
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that’s correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I move cfinite_sequence
, too, or in a different PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I would normally say it’s better to move it in a different PR, we can just get it done here
No problem! I'm amazed and it really makes me happy that you do thorough reviews!
I put the I agree that a finite precision version won't happen. We could have The reason for not advocating: |
Co-authored-by: Travis Scrimshaw <[email protected]>
I don’t think the lazy in from makes it very discoverable compared to the API we have for similar such objects (mainly |
Just a brief update: I am not sure. Essentially, that does mean that we should make Another thing I just noticed is that I guess we could first leave things as they are (perhaps rename |
In the sense of a common abstract class and creation (with the default precision being passed as
Hmm….that’s really annoying. We can’t really just do a drop-in replacement as it has different API, right? We could do a 2 step deprecation: the |
I would like to move on here. Meanwhile, I have also implemented the arithmetic product. I agreed to give an online course on enumeration with sagemath at 128.5, but I guess it is too late to have this even in develop. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, we can merge this now. I would like to deprecate LazyCombinatorialSpecies
once we have the full replacement for the old version ready, but we can address that at that time.
Thank you! |
sagemathgh-38544: Lazy species We provide an implementation of combinatorial species based on the lazy series framework and sagemath#38446. dependencies: sagemath#38974 URL: sagemath#38544 Reported by: Martin Rubey Reviewer(s): Martin Rubey, Travis Scrimshaw
sagemathgh-38544: Lazy species We provide an implementation of combinatorial species based on the lazy series framework and sagemath#38446. dependencies: sagemath#38974 URL: sagemath#38544 Reported by: Martin Rubey Reviewer(s): Martin Rubey, Travis Scrimshaw
We provide an implementation of combinatorial species based on the lazy series framework and #38446.
dependencies: #38974