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
Provide a simple (and generic) way to create immutable vectors and matrices #25509
Comments
Author: Julian Ritter |
Commit: |
Changed keywords from none to vector, matrix, immutable |
comment:3
I personally do not see the advantage to just setting the matrix/vector immutable, once I'm done modifying it. Are there other examples (than graphs) that do it with keywords? |
comment:4
Replying to @kliem:
It would avoid introducing a variable just to make this adjustment. This can simplify code by more than just one line. Consider, for example, list/set/dict comprehensions and compare
to
I did a quick research. Apart from
Apart from
Just like @mantepse, I would prefer |
comment:5
Thank you for implementing this. Personally, I have been missing this option several times and was surprised it did not exist. The
|
comment:6
Thanks. Especially the example illustrated to me, why such a switch makes sense. Maybe you could add this example to the description of the ticket. I'm not into matrices or vectors too much (I never contributed to them). So if I'm going to agree to adding a switch, I want to know, that it is useful. I never had a striking reason against adding the Some more remarks:
- sage: matrix is immutable; please change a copy instead (i.e., use copy(M) to change a copy of M).
+ ValueError: matrix is immutable; please change a copy instead (i.e., use copy(M) to change a copy of M).
- if kwds.pop('immutable', False):
- M = MatrixArgs(*args, **kwds).matrix()
- M.set_immutable()
- return M
-
- return MatrixArgs(*args, **kwds).matrix()
+ immutable = kwds.pop('immutable', False)
+ M = MatrixArgs(*args, **kwds).matrix()
+ if immutable:
+ M.set_immutable()
+ return M The reason I'm suggesting it: It is clearer, what the switch immutable does. It doesn't effect the construction of the matrix, it is just setting the matrix immutable, after the construction.
Otherwise, this looks fine modulo the changes suggested by Markus Wageringel. Maybe one could add tiny tests for each case of the early returns. Replying to @sagetrac-nailuj:
|
comment:9
Ticket retargeted after milestone closed |
Branch pushed to git repo; I updated commit sha1. New commits:
|
This comment has been minimized.
This comment has been minimized.
comment:11
I made all the proposed adjustments. This should be ready for review. While working on the early returns, I noticed that |
comment:12
I don't feel very strongly about this point, but EDIT: as pointed out, consistency is important and for graphs it looks like |
comment:13
Replying to @nbruin:
I think it should be consistent with graphs (either way). |
comment:14
Your missing the colons after Also I think, error message should not end with a period. I think returning |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:16
Replying to @kliem:
Thank you, I only tested the vector file. I fixed it.
Could you be more specific? I don't think I introduced any error message.
Thanks! |
comment:17
LGTM. |
Reviewer: Jonathan Kliem |
Changed branch from u/nailuj/immutable_vectors_and_matrices to |
We currently have the following elegant way to produce immutable graphs:
The aim of this ticket is to have the same for other objects, in particular vectors and matrices.
It would avoid introducing a variable just to make this adjustment. This can simplify code by more than just one line. Consider, for example, list/set/dict comprehensions and compare
to
CC: @kliem
Component: misc
Keywords: vector, matrix, immutable
Author: Julian Ritter
Branch/Commit:
5e110ad
Reviewer: Jonathan Kliem
Issue created by migration from https://trac.sagemath.org/ticket/25509
The text was updated successfully, but these errors were encountered: