Skip to content

Faster implementation of is_invertible() by checking full rank #39876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/sage/matrix/matrix_gf2e_dense.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,22 @@
break
return pivots

def is_invertible(self):
"""
Return ``True`` if this matrix is invertible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an algorithm block if you want to say how this works internally:

Suggested change
ALGORITHM: this checks that the matrix is square and has full rank. This is to circumvent the determinant computation used by the general method :meth:`sage.matrix.matrix0.Matrix.is_invertible`, since currently there is no efficient determinant implementation in this class of matrices.

EXAMPLES::

sage: m = Matrix(GL(2^8, GF(2^8)).random_element())

Check warning on line 972 in src/sage/matrix/matrix_gf2e_dense.pyx

View workflow job for this annotation

GitHub Actions / Conda (ubuntu, Python 3.12, new)

Warning: slow doctest:

slow doctest:
sage: m.is_invertible()
True
"""
if self._ncols != self._nrows:
return False
if self._nrows != self.rank():
return False
return True

def __invert__(self):
"""
EXAMPLES::
Expand All @@ -980,7 +996,7 @@
cdef Matrix_gf2e_dense A
A = Matrix_gf2e_dense.__new__(Matrix_gf2e_dense, self._parent, 0, 0, 0)

if self.rank() != self._nrows:
if not self.is_invertible():
raise ZeroDivisionError("Matrix does not have full rank.")

if self._nrows:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing this if?

Expand Down
Loading