Opened 2 years ago

Last modified 5 months ago

#30302 new task

Always Return a Copy — at Initial Version

Reported by: gh-mjungmath Owned by:
Priority: major Milestone: sage-9.7
Component: misc Keywords:
Cc: egourgoulhon, tscrim, mkoeppe Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

This question arose from ticket #30239, comment:36.

Should FiniteRankFreeModule and manifold object always return a mutable copy, even for trivial operations? At least, this would be a consistent behavior.

As pointed out by Matthias, this already holds true for FreeModule:

sage: M = FreeModule(QQ, 3)
sage: v = M([1,2,3])
sage: w = v + 0
sage: w == v
True
sage: w is v
False

I feel quite torn about this, but tend to the copy-version.

Addendum:

For FreeModule, we also have the following behavior:

sage: M = FreeModule(QQ, 3)
sage: M(0)
(0, 0, 0)
sage: M.zero()
(0, 0, 0)
sage: M.zero() is M(0)
False

I don't think that a parent should do that, especially when it already has a zero method. Should that be changed?

Change History (0)

Note: See TracTickets for help on using tickets.