Mutability of matrices with no entries

54 views
Skip to first unread message

Andrey Novoseltsev

unread,
Jul 31, 2015, 7:51:12 PM7/31/15
to sage-devel
Hello,

While working on http://trac.sagemath.org/ticket/18613 I ran into the following problem:

sage: matrix(2, 1).echelon_form().is_mutable()
False
sage: matrix(2, 0).echelon_form().is_mutable()
True

i.e. while usually echelon_form returns an immutable matrix this is not the case with trivial ones. The reason is in the beginning of its code:

        if self._nrows == 0 or self._ncols == 0:
            self.cache('pivots', ())
            self.cache('rank', 0)
            if transformation:
                return self, self
            return self

The question is how to fix it:
1) make here a copy of self, set it to be immutable, and return it
2) make self immutable and return self
3) always make matrices without elements immutable (not sure if this can be done in one place or in several implementations)

It seems that 3) is the most sensible, but what if some code checks for the ability to change a matrix a refuses to work with immutable ones? Any suggestions?

Thank you!
Andrey

Volker Braun

unread,
Aug 1, 2015, 4:50:01 AM8/1/15
to sage-devel
The principle of least surprise would suggest that mutability should follow the same rules independent of the matrix size. And echelon_form should always return an immutable matrix.

Andrey Novoseltsev

unread,
Aug 12, 2015, 6:08:41 PM8/12/15
to sage-devel
Ready for review - I've ended up rewriting quite a bit in echelon_form
Reply all
Reply to author
Forward
0 new messages