Skip to content

Commit e47e21f

Browse files
committed
fix styles and add cython typing
1 parent d09a8b1 commit e47e21f

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

src/sage/matrix/matrix_mod2_dense.pyx

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,18 +2148,18 @@ cdef class Matrix_mod2_dense(matrix_dense.Matrix_dense): # dense or sparse
21482148
21492149
- ``inplace`` -- boolean (default: ``False``); using ``inplace=True``
21502150
will permute the rows and columns of the current matrix
2151-
according to a doubly lexical ordering. This will modify the matrix.
2151+
according to a doubly lexical ordering; this will modify the matrix
21522152
21532153
OUTPUT:
21542154
2155-
Returns a pair (``row_ordering``, ``col_ordering``). Each item
2156-
is a ``PermutationGroupElement`` that represents a doubly lexical
2157-
ordering of the rows or columns.
2155+
A pair ``(row_ordering, col_ordering)`` of
2156+
:class:`~sage.groups.perm_gps.constructor.PermutationGroupElement`
2157+
that represents a doubly lexical ordering of the rows or columns.
21582158
21592159
.. SEEALSO::
21602160
2161-
- :meth:`~sage.matrix.matrix2.Matrix.permutation_normal_form` --
2162-
a similar matrix normal form
2161+
:meth:`~sage.matrix.matrix2.Matrix.permutation_normal_form`;
2162+
a similar matrix normal form
21632163
21642164
ALGORITHM:
21652165
@@ -2204,27 +2204,18 @@ cdef class Matrix_mod2_dense(matrix_dense.Matrix_dense): # dense or sparse
22042204
....: [0, 0, 0, 1, 1, 1, 0]])
22052205
sage: r, c = A.doubly_lexical_ordering()
22062206
sage: B = A.with_permuted_rows_and_columns(r, c)
2207-
sage: flag = True
22082207
sage: for i in range(B.ncols()):
22092208
....: for j in range(i):
22102209
....: for k in reversed(range(B.nrows())):
2211-
....: if B[k][j] > B[k][i]:
2212-
....: flag = False
2213-
....: break
2210+
....: assert B[k][j] <= B[k][i]
22142211
....: if B[k][j] < B[k][i]:
22152212
....: break
2216-
sage: flag
2217-
True
22182213
sage: for i in range(B.nrows()):
22192214
....: for j in range(i):
22202215
....: for k in reversed(range(B.ncols())):
2221-
....: if B[j][k] > B[i][k]:
2222-
....: flag = False
2223-
....: break
2216+
....: assert B[j][k] <= B[i][k]
22242217
....: if B[j][k] < B[i][k]:
22252218
....: break
2226-
sage: flag
2227-
True
22282219
sage: r, c = A.doubly_lexical_ordering(inplace=True)
22292220
sage: A == B
22302221
True
@@ -2235,25 +2226,26 @@ cdef class Matrix_mod2_dense(matrix_dense.Matrix_dense): # dense or sparse
22352226
sage: r, c = A.doubly_lexical_ordering(inplace=True)
22362227
Traceback (most recent call last):
22372228
...
2238-
TypeError: This matrix is immutable and can thus not be changed.
2239-
Use inplace=False or create a mutable copy.
2229+
TypeError: this matrix is immutable;
2230+
use inplace=False or apply to a mutable copy.
22402231
"""
22412232

22422233
if inplace and self.is_immutable():
2243-
raise TypeError("This matrix is immutable and can thus not be changed."
2244-
" Use inplace=False or create a mutable copy.")
2234+
raise TypeError("this matrix is immutable;"
2235+
" use inplace=False or apply to a mutable copy.")
22452236

2246-
partition_rows = [False for _ in range(self._nrows - 1)]
2247-
partition_num = 1
2248-
row_swapped = list(range(1, self._nrows + 1))
2249-
col_swapped = list(range(1, self._ncols + 1))
2237+
cdef list partition_rows = [False for _ in range(self._nrows - 1)]
2238+
cdef int partition_num = 1
2239+
cdef list row_swapped = list(range(1, self._nrows + 1))
2240+
cdef list col_swapped = list(range(1, self._ncols + 1))
22502241

22512242
cdef Matrix_mod2_dense A = self if inplace else self.__copy__()
22522243

2244+
cdef int i, col, row, partition_i, partition_start, partition_end
2245+
cdef int largest_col, row_start, row_end
22532246
for i in reversed(range(1, A._ncols + 1)):
2254-
22552247
# count 1 for each partition and column
2256-
count1 = [[0 for _ in range(partition_num)] for _ in range(i)]
2248+
count1 = [[0]*partition_num for _ in range(i)]
22572249
for col in range(i):
22582250
parition_i = 0
22592251
for row in reversed(range(A._nrows)):

0 commit comments

Comments
 (0)