Skip to content

Commit 09f397a

Browse files
author
Release Manager
committed
gh-39876: Faster implementation of is_invertible() by checking full rank #31274 As mentioned in the issue, a faster invertibility check for matrix in `Matrix_gf2e_dense` by checking full rank. <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes #12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes #12345". --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #39876 Reported by: Henry Wu Reviewer(s): user202729, Vincent Neiger
2 parents a6c3526 + cce4350 commit 09f397a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/sage/matrix/matrix_gf2e_dense.pyx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,22 @@ cdef class Matrix_gf2e_dense(matrix_dense.Matrix_dense):
10041004
break
10051005
return pivots
10061006

1007+
def is_invertible(self):
1008+
"""
1009+
Return ``True`` if this matrix is invertible.
1010+
1011+
EXAMPLES::
1012+
1013+
sage: m = Matrix(GL(2^8, GF(2^8)).random_element())
1014+
sage: m.is_invertible()
1015+
True
1016+
"""
1017+
if self._ncols != self._nrows:
1018+
return False
1019+
if self._nrows != self.rank():
1020+
return False
1021+
return True
1022+
10071023
def __invert__(self):
10081024
"""
10091025
EXAMPLES::
@@ -1021,7 +1037,7 @@ cdef class Matrix_gf2e_dense(matrix_dense.Matrix_dense):
10211037
cdef Matrix_gf2e_dense A
10221038
A = Matrix_gf2e_dense.__new__(Matrix_gf2e_dense, self._parent, 0, 0, 0)
10231039

1024-
if self.rank() != self._nrows:
1040+
if not self.is_invertible():
10251041
raise ZeroDivisionError("Matrix does not have full rank.")
10261042

10271043
if self._nrows:

0 commit comments

Comments
 (0)