Skip to content

Commit dfd55a8

Browse files
author
Release Manager
committed
sagemathgh-39757: Ensure _charpoly_df is interruptible As in the title. Note that `sig_check()` is only called every `O(t)` ring operations, but each of them should be `O(1)`, otherwise the implementation of the ring operation itself ought to check it… I think. Or do you think it's better to check every iteration instead? ### 📝 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. - [ ] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#39757 Reported by: user202729 Reviewer(s): Travis Scrimshaw
2 parents 2fa9c97 + 9d8454a commit dfd55a8

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/sage/matrix/matrix2.pyx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3291,6 +3291,16 @@ cdef class Matrix(Matrix1):
32913291
sage: A._charpoly_df()
32923292
x^3 + 8*x^2 + 10*x + 1
32933293

3294+
.. NOTE::
3295+
3296+
The key feature of this implementation is that it is division-free.
3297+
This means that it can be used as a generic implementation for any
3298+
ring (commutative and with multiplicative identity). The algorithm
3299+
is described in full detail as Algorithm 3.1 in [Sei2002]_.
3300+
3301+
Note that there is a missing minus sign in front of the last term in
3302+
the penultimate line of Algorithm 3.1.
3303+
32943304
TESTS::
32953305

32963306
sage: A = matrix(ZZ, 0, 0)
@@ -3309,15 +3319,11 @@ cdef class Matrix(Matrix1):
33093319
sage: matrix(4, 4, lambda i, j: R.an_element())._charpoly_df() # needs sage.combinat
33103320
B[1]*x^4 - 4*B[u]*x^3
33113321

3312-
.. NOTE::
3322+
Test that the function is interruptible::
33133323

3314-
The key feature of this implementation is that it is division-free.
3315-
This means that it can be used as a generic implementation for any
3316-
ring (commutative and with multiplicative identity). The algorithm
3317-
is described in full detail as Algorithm 3.1 in [Sei2002]_.
3318-
3319-
Note that there is a missing minus sign in front of the last term in
3320-
the penultimate line of Algorithm 3.1.
3324+
sage: m = matrix.random(RR, 128)
3325+
sage: from sage.doctest.util import ensure_interruptible_after
3326+
sage: with ensure_interruptible_after(1): m.charpoly()
33213327
"""
33223328

33233329
# Validate assertions
@@ -3374,6 +3380,7 @@ cdef class Matrix(Matrix1):
33743380
for j in range(t+1):
33753381
s = s + M.get_unsafe(i, j) * a.get_unsafe(p-1, j)
33763382
a.set_unsafe(p, i, s)
3383+
sig_check()
33773384

33783385
# Set A[p, t] to be the (t)th entry in a[p, t]
33793386
A[p] = a.get_unsafe(p, t)

0 commit comments

Comments
 (0)