Opened 3 years ago
Last modified 3 years ago
#23436 new defect
sum/product of immutable matrices is not immutable
Reported by: | dkrenn | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-8.1 |
Component: | linear algebra | Keywords: | matrix |
Cc: | galipnik | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
sage: M = Matrix([[1,2],[3,4]]); M.set_immutable() sage: N = Matrix([[2,2],[4,4]]); N.set_immutable() sage: (M + N).is_immutable() False sage: (M * N).is_immutable() False
This is counter-intuitive. The result should again be immutable.
Change History (3)
comment:1 Changed 3 years ago by
- Cc galipnik added
comment:2 follow-up: ↓ 3 Changed 3 years ago by
comment:3 in reply to: ↑ 2 Changed 3 years ago by
Replying to jdemeyer:
For reference, this is how Python deals with it (
frozenset
being an immutable version ofset
):>>> frozenset([1,2,3]) | frozenset([4,5,6]) frozenset({1, 2, 3, 4, 5, 6}) >>> frozenset([1,2,3]) | set([4,5,6]) frozenset({1, 2, 3, 4, 5, 6}) >>> set([1,2,3]) | frozenset([4,5,6]) {1, 2, 3, 4, 5, 6} >>> set([1,2,3]) | set([4,5,6]) {1, 2, 3, 4, 5, 6}So the mutability of
A | B
is taken from the mutability ofA
.
Is this the desired behavior or should it be that if either is immutable than the resultant should be as well? For example, this is how networkx handles a graph product of a undirected and directed graph (in either order).
Note: See
TracTickets for help on using
tickets.
For reference, this is how Python deals with it (
frozenset
being an immutable version ofset
):So the mutability of
A | B
is taken from the mutability ofA
.