#8276: Make the one(), identity_matrix() and zero_matrix() cached and immutable.
------------------------------+---------------------------------------------
Reporter: hivert | Owner: hivert
Type: defect | Status: needs_review
Priority: major | Milestone: sage-4.3.3
Component: linear algebra | Keywords: One mutable.
Author: Florent Hivert | Upstream: N/A
Reviewer: | Merged:
Work_issues: |
------------------------------+---------------------------------------------
Comment(by hivert):
Replying to [comment:12 rossk]:
> *Almost* everything seems straightforward and correct but...
Sure ! What wasn't straightforward was to correctly find all the places
which needed to be patched and to distinguish them from those who doesn't.
Note that the speed regression when calling {{{copy(MM.zero_matrix())}}}
is due to a missing optimization in cached_method which should be added
soon.
> Seems that MM(0) which has a "mutable == True" property/value should be
updatable but the example "MM(0)[1,2] = 3" doesnt update MM(0) (see
example below) Is that right?[[BR]]
{{{
> sage: MM(0)
> [0 0 0]
> [0 0 0]
> [0 0 0]
>
> sage: MM(0)[1,2]=3
>
> # this behavior is the same before and after patches were applied
> # is this right? isnt MM(0) mutable and should be = 3 at row/col=[1,2]?
> sage: MM(0)
> [0 0 0]
> [0 0 0]
> [0 0 0]
}}}
This is perfectly normal. {{{MM(0)}}} does not design a particular matrix
object. It construct a brand new matrix. So that
{{{
sage: MM(0)[1,2]=3
}}}
Construct a matrix, modify it and forget about the result so that the next
call to
{{{MM(0)}}} gives you a brand new zero matrix. To achieve what you want
you should write
{{{
sage: MM = MatrixSpace(ZZ, 3,3)
sage: mat = MM(0); mat[1,2]=3
sage: mat
[0 0 0]
[0 0 3]
[0 0 0]
}}}
Florent
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/8276#comment:14>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.