On Mon, Feb 15, 2010 at 1:19 PM, Florent Hivert
<florent.hiv...@univ-rouen.fr> wrote:
>      Hi there,
>
> I have a slightly stupid question ! First of all consider the following
> behavior (sage 4.3.2):
>
> sage: A = MatrixSpace(ZZ, 3)
> sage: A.one()
> [1 0 0]
> [0 1 0]
> [0 0 1]
> sage: A.one()[1,2] = 1
> sage: A.one()
> [1 0 0]
> [0 1 1]
> [0 0 1]
>
> This is definitely bad. It happens because one is generically computed by
> coercion from 1 and then cached without making it immutable. I see at least
> three solutions:
>
>  1. - Don't cache at all
>  2. - Return a cached immutable

I strongly vote for 2.

>  3. - Return a mutable copy of a cached
>
> To have an idea of the usage I went trough the code:
>
>  - MatrixSpace.identity_matrix implement 1.
>  - MatrixSpace.zero_matrix implement 3.
>
> Of course, my opinion is to make those three methods implements 2. :-)

+1

> Any arguments in favor one or one other ?

I like 2.  If you need a copy to mutate, then you can always do A.one().copy().

William

>
> Cheers,
>
> Florent
>
> --
> 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
>



-- 
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

-- 
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