-
-
Notifications
You must be signed in to change notification settings - Fork 435
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
copy(CombinatorialFreeModule.Element) broken by #22632 #23075
Comments
comment:1
Thanks for the report. Hmm, that's due to the fact that _monomial_coefficients is a Cython attribute now, so not automatically copied. So we need a custom What's the use case where this showed up? |
comment:2
Replying to @nthiery:
I was reparenting an element from one module to a slightly altered clone of its parent (so I was probably violating the immutability assumption regarding elements, of which I was unaware). My code was similar to this: def corresponding_element_in_clone(parent,elem):
N = parent.create_modified_clone(parent)
x = copy(elem)
x._set_parent(N)
return x Using "deepcopy" seems to still work. |
comment:3
Well, I would say yes and no. By copying the object, you're going around the immutability by making a temporarily mutable object. This isn't quite your question, but if you wanted to (safely) manipulate the underlying However, the fact that |
comment:4
Thanks for the feedback. I agree with Travis. Let's go for an idempotent copy operator. Do you see a natural place to advertise that the elements are immutable? |
comment:5
For the most part, elements in Sage are considered immutable so we can do hashing, but I guess this conflicts with the rest of the linear algebra in Sage. So I would put a small note/example in the |
comment:7
Setting new milestone based on a cursory review of ticket status, priority, and last modification date. |
comment:11
Still broken in 9.7.beta8 |
comment:12
--- a/src/sage/combinat/free_module.py
+++ b/src/sage/combinat/free_module.py
@@ -358,10 +358,12 @@
sage: A.__class__.element_class.__module__
'sage.combinat.free_module'
"""
- return self.__make_element_class__(self.Element,
+ cls = self.__make_element_class__(self.Element,
name="%s.element_class" % self.__class__.__name__,
module=self.__class__.__module__,
inherit=True)
+ setattr(cls, '__copy__', lambda x: x)
+ return cls
def __init__(self, R, basis_keys=None, element_class=None, category=None,
prefix=None, names=None, **kwds): |
comment:13
Very strong -1 on the comment:12 proposal. It is a hack and only applies to I think it should be sufficient to do
in |
comment:14
Are CFM elements immutable? |
comment:15
Yes, like most (all?) other elements in Sage (other than matrices, vectors, and (di)graphs). |
comment:16
Then |
This comment has been minimized.
This comment has been minimized.
comment:18
Here are the methods. I am now leaning towards not really saying anything because it doesn't implement any of the other mutability operations than New commits:
|
Commit: |
Author: Travis Scrimshaw |
comment:19
Looking good, with the nitpick that "copy" is not only idempotent here but actually the identity. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:21
Replying to @mkoeppe:
Fair enough. I have changed it. |
comment:22
just waiting for a green bot |
Reviewer: Matthias Koeppe |
comment:24
Thank you. |
Changed branch from public/linear_algebra/indexed_elt_copy-23075 to |
The following problem showed up with 8.0.beta8: the copy of an IndexedFreeModuleElement seems to be not functional:
Part of Meta-ticket #13811: Support Python's
__copy__
/__deepcopy__
protocolCC: @nthiery @jdemeyer @fchapoton @tscrim @mjungmath
Component: combinatorics
Author: Travis Scrimshaw
Branch/Commit:
ac1bf2c
Reviewer: Matthias Koeppe
Issue created by migration from https://trac.sagemath.org/ticket/23075
The text was updated successfully, but these errors were encountered: