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
Enhance the e_one_star.Patch class #11255
Comments
comment:1
Attachment: trac-11255-tj.patch.gz For the patchbot : Apply trac-11255-tj.patch |
Salut Timo, Below are my comments.
Instead of writing a sentence about the input, I prefer if we follow the Sage Developper's Guide and write an INPUT section. No need to import E1Star in the doctest of the remove method.
I have some concerns about adding a hash method to the Patch class. Since a patch can be modified (by using the remove method for instance), strange behavior can occur like the following :
Any serious Python or Sage object is either mutable and unhashable or immutable and hashable. In Sage, matrices and vector are allowed to pass from one state to the other using methods like
Can you provide an example that justifies the modification? Without an example, I can not say that I agree with the solution. I feel like the solution is doing too much copies. But, I can't suggest an alternative, since I do not know what the problem really is. Once the problem is solved, such an example illustrating the problem you mention must be added as a doctest. And finally, I do not understand this modification : - return (isinstance(other, Patch) and set(self) == set(other))
+ return (isinstance(other, Patch) and set(self._faces) == set(other._faces)) |
comment:5
Replying to @seblabbe:
I agree, I corrected this.
Thanks for mentionning this. I corrected many other instances of the same issue.
Here is why I added a
I had a lot of problems because of this when I used some
Here is the problem with colors if we don't create new faces in Patch.init:
Let me know if you have a better solution. I added it in the doctest under a TEST section.
OK, I reverted this useless modification (something I had tested but forgot to remove). Please tell me if you agree with what I said concerning the main two issues you raised ( Also, do you think the following code of
|
comment:6
If we want Patches to be keys of dictionnary, vertices of graphs or elements of There are three methods that change self : Now, the method
One can create a Patch from a (1) iterable of faces or (2) from a Patch. The
First, there is a problem with the method
Hence, I suggest to implement a method called My last question concerns the representation of the Patch. Now, we represent a
What do you think? Sébastien |
comment:7
This problem would be solved by using a frozenset instead of a list for representing a Patch. |
comment:8
Replying to @seblabbe:
OK, these methods now return a new patch, along with a deprecation warning.
This is a good solution, I use it.
OK, I this is also a better solution. I also added a
Everything is cleaner if we use sets instead of lists, you're right. I submitted a new patch that uses frozenset and made the according changes in the doc and everywhere, which means quite a lot of stuff as you will see in my new patch, which applies over the previous one. Also, I added an option in Thank you for your very useful corrections. For the patchbot : Apply trac-11255-tj.patch Apply trac-11255-tj-modifs.patch |
applies over the first patch |
comment:9
Attachment: trac-11255-tj-modifs.patch.gz Dear Sébastien, I just added a |
This comment has been minimized.
This comment has been minimized.
Attachment: trac_11255_reviewer-sl.patch.gz Applies over the precedent 2 patches |
comment:11
I just added a reviewer patch which applies over the precedent two. There was doctest errors with the hash method (I obtain different hash results on my machine). I still have concerns with two things before giving a positive review : (1) I think the method |
comment:12
Hi, thanks for you corrections and your patch.
I would like to keep the I will soon make the changes to the doc to prevent the |
This comment has been minimized.
This comment has been minimized.
comment:13
Hi, Four things: I have solved all the doc problems related to the fact that The I optimized a little the Also, I have been more careful about making new Faces when creating new Patches. It is not enough to create new Faces only when |
comment:14
Salut Timo, Excuse-moi pour la dernière semaine, j'aurais dû te répondre avant.
I still have problem with that. By implementing I have another argument. Not only it may affect the doctests depending on the machine as I said earlier. But also, and more importantly, it affects the fiability of the code someone write. I know you know the warning. But such a warning is not natural for the method getitem. Hence, some user will write code, send it to a friend, and it might be broken. In other words, implement
You solved it by just adding
OK
OK. Fine. But now, I think we are doing too much. How many copies of copies do we need to be safe? I think one is enough. For instance, here : - return Patch(self._faces.difference(other))
+ P = Patch(self)
+ Q = Patch(other)
+ return Patch(P._faces.difference(Q)) The line |
comment:15
Again, add such an example in the doctests. Sébastien |
comment:16
Replying to @seblabbe:
OK, there is no more
No, the code is tested as it should (even the length of the returned string is tested). Only
There were indeed too many copies, I changed that. I uploaded a new version of the last patch. Cheers, |
Attachment: trac_11255_modifs2-tj.patch.gz |
comment:17
To get the first element, you can do:
To get the i-th element:
I look at your patch and review it soon. Je crois bien qu'on y est maintenant! Sébastien |
comment:18
I just upload a patch which applies over all the precedent ones. The positive - return [face for face in self if face.vector() == vector(v)]
+ return [Face(f.vector(), f.type(), f.color()) for f in self if f.vector() == vector(v)] - return [face for face in self if face.type() == t]
+ return [Face(f.vector(), f.type(), f.color()) for f in self if f.type() == t] Why do we need copies in those cases? Sébastien |
This comment has been minimized.
This comment has been minimized.
Reviewer: Sébastien Labbé |
comment:20
Replying to @seblabbe:
Hi, if for some reason the user repaints the returned faces, we don't want it to change the color of the faces in the original Patch. Otherwise, are you sure about the
|
comment:21
|
comment:22
I feel I should and could be cited as an author of the file Sébastien |
comment:23
Replying to @seblabbe:
Of course! I thought so since the work we had done in Porquerolles but you wanted to be a reviewer instead. It's good that you added yourself. Otherwise, I agree with the other changes of your last patch. |
comment:24
Replying to @sagetrac-tjolivet:
What if the user wants to get the faces of a certain type and does not want to repaint them? We do useless copies in that case. I feel like those methods should return the faces as they are. I think the user may make the copies himself. It is like if the patch was a Python set. Iterating through it iterates through its elements (not copies of them).
Sébastien |
comment:25
Replying to @seblabbe:
OK, I agree. If Oh, I think we should also add a method
|
Attachment: trac_11255_reviewer-2nd-sl.patch.gz Applies over the precedent patches |
comment:26
I am ready to give a positive review to this ticket. But before, Timo, you must check my last patch. Sébastien |
comment:27
Replying to @seblabbe:
Very good, I agree! Thanks a lot. |
This comment has been minimized.
This comment has been minimized.
Merged: sage-4.7.1.alpha3 |
A few enhancements for the Patch class:
remove
method;__hash__
method;For the patchbot (this info must be put here instead of below):
Apply:
CC: @seblabbe
Component: combinatorics
Author: Timo Jolivet
Reviewer: Sébastien Labbé
Merged: sage-4.7.1.alpha3
Issue created by migration from https://trac.sagemath.org/ticket/11255
The text was updated successfully, but these errors were encountered: