Skip to content

Commit 3b9f87c

Browse files
committed
raise an error if an immutable matrix with inplace=True
1 parent df75932 commit 3b9f87c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/sage/matrix/matrix_mod2_dense.pyx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,8 +2226,20 @@ cdef class Matrix_mod2_dense(matrix_dense.Matrix_dense): # dense or sparse
22262226
sage: A == B
22272227
True
22282228
2229+
An immutable matrix calling with ``inplace=True`` will raise an error::
2230+
2231+
sage: A = Matrix(GF(2), [[0, 1], [1, 0]], immutable=True)
2232+
sage: r, c = A.doubly_lexical_ordering(inplace=True)
2233+
Traceback (most recent call last):
2234+
...
2235+
TypeError: This matrix is immutable and can thus not be changed. Use inplace=False or create a mutable copy.
2236+
22292237
"""
22302238

2239+
if inplace and self.is_immutable():
2240+
raise TypeError("This matrix is immutable and can thus not be changed."
2241+
" Use inplace=False or create a mutable copy.")
2242+
22312243
partition_rows = [False for _ in range(self._nrows - 1)]
22322244
partition_num = 1
22332245
row_swapped = list(range(1, self._nrows + 1))

0 commit comments

Comments
 (0)