On Jun 10, 2010, at 11:50 PM, William Stein wrote:

On Thu, Jun 10, 2010 at 10:58 PM, Robert Bradshaw
<rober...@math.washington.edu> wrote:

On Jun 10, 2010, at 8:17 PM, Jason Grout wrote:

On 6/10/10 12:25 PM, Florent Hivert wrote:

     Hi There,

I'd like to discuss a design question. Some time ago Adrien Boussicault
and
myself started to write some experimental code for copy-on-write in
Sage/Python. The idea is now more or less dropped because performance
gain was
not so good and the syntax was not very usable.

Rob and I were just talking yesterday how it's so inconvenient that
identity_matrix() now returns an immutable matrix, so constructing something from it involves making a copy, which is not the most obvious thing to a new person, or the most elegant thing to someone that has been using matrices
for a while now.  It would be fantastic if immutable matrices had
copy-on-write semantics, not necessarily for performance, but just for usability after some of the recent design decisions (which I guess were made
for performance reasons).

Copy on write *should* be rather easy to implement for matrices at least.

Just out of curiosity, is this what would happen below with what you
guys are envisioning
for immutable copy on write matrices?

sage: a = matrix(ZZ, 3)
sage: a[1,2] = 5
sage: a.set_immutable()
sage: a[1,2] = 7
sage: print a
7

No, I was thinking that one would still have to do m.copy(), but the actual copying would only occur the first time the matrix entries were mutated. Thus methods like one() and zero() would return mutable copies without the overhead of actually copying.

If so, what about:

sage: A = M.hecke_matrix(2)
sage: A[1,2]
20
sage: A[1,2] = 5; A
5
sage: M.hecke_matrix(2)[1,2]
20

I think the above would be very, very confusing to me.

But A is no longer the Hecke matrix--so I wouldn't expect it to be equal to the Hecke matrix as recomputed on the last line.

If immutable
matrices *act* as if they are fully mutable, but basically silently
have completely different semantics, this will be confusing.

The above makes perfect sense to me--whenever I do

sage: X = foo()
sage: # mutate X

I *don't* expect future calls to foo() to be mangled, rather I expect it to be recomputed (or, if cached, acting as it if were recomputed). In fact, most of the time this happens I'd call it a bug, which is why we try so hard to return copies of lists, or tuples, and one of the primary motivations for immutable matrices in the first place.

- Robert

--
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to