Skip to content

Commit f7e9833

Browse files
author
Release Manager
committed
gh-36070: `sage.{matrix,modules,probability,stats,quadratic_forms,tensor}`: Update `# needs`, modularization fixes <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> Also defining new features `sage.libs.linbox`, `sage.libs.m4ri`. <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> - Part of: #29705 - Cherry-picked from: #35095 <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [ ] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #36070 Reported by: Matthias Köppe Reviewer(s): David Coudert, Matthias Köppe
2 parents 48a4551 + 4c4d62f commit f7e9833

File tree

110 files changed

+4428
-3581
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+4428
-3581
lines changed

src/sage/features/sagemath.py

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,67 @@ def __init__(self):
392392
PythonModule('sage.interfaces.gap')])
393393

394394

395+
class sage__libs__linbox(JoinFeature):
396+
r"""
397+
A :class:`sage.features.Feature` describing the presence of :mod:`sage.libs.linbox`
398+
and other modules depending on Givaro, FFLAS-FFPACK, LinBox.
399+
400+
In addition to the modularization purposes that this tag serves,
401+
it also provides attribution to the upstream project.
402+
403+
TESTS::
404+
405+
sage: from sage.features.sagemath import sage__libs__linbox
406+
sage: sage__libs__linbox().is_present() # needs sage.libs.linbox
407+
FeatureTestResult('sage.libs.linbox', True)
408+
"""
409+
def __init__(self):
410+
r"""
411+
TESTS::
412+
413+
sage: from sage.features.sagemath import sage__libs__linbox
414+
sage: isinstance(sage__libs__linbox(), sage__libs__linbox)
415+
True
416+
"""
417+
JoinFeature.__init__(self, 'sage.libs.linbox',
418+
[PythonModule('sage.rings.finite_rings.element_givaro')],
419+
spkg='sagemath_linbox', type='standard')
420+
421+
422+
class sage__libs__m4ri(JoinFeature):
423+
r"""
424+
A :class:`sage.features.Feature` describing the presence of Cython modules
425+
depending on the M4RI and/or M4RIe libraries.
426+
427+
In addition to the modularization purposes that this tag serves,
428+
it also provides attribution to the upstream project.
429+
430+
TESTS::
431+
432+
sage: from sage.features.sagemath import sage__libs__m4ri
433+
sage: sage__libs__m4ri().is_present() # needs sage.libs.m4ri
434+
FeatureTestResult('sage.libs.m4ri', True)
435+
"""
436+
def __init__(self):
437+
r"""
438+
TESTS::
439+
440+
sage: from sage.features.sagemath import sage__libs__m4ri
441+
sage: isinstance(sage__libs__m4ri(), sage__libs__m4ri)
442+
True
443+
"""
444+
JoinFeature.__init__(self, 'sage.libs.m4ri',
445+
[PythonModule('sage.matrix.matrix_gf2e_dense')],
446+
spkg='sagemath_m4ri', type='standard')
447+
448+
395449
class sage__libs__ntl(JoinFeature):
396450
r"""
397451
A :class:`sage.features.Feature` describing the presence of :mod:`sage.libs.ntl`
398-
and other modules depending on NTL and arb.
452+
and other modules depending on NTL.
399453
400-
In addition to the modularization purposes that this tag serves, it also provides attribution
401-
to the upstream project.
454+
In addition to the modularization purposes that this tag serves,
455+
it also provides attribution to the upstream project.
402456
403457
TESTS::
404458
@@ -423,11 +477,12 @@ class sage__libs__pari(JoinFeature):
423477
r"""
424478
A :class:`~sage.features.Feature` describing the presence of :mod:`sage.libs.pari`.
425479
426-
SageMath uses the :ref:`PARI <spkg_pari>` library (via :ref:`cypari2 <spkg_cypari>`) for numerous purposes.
427-
Doctests that involves such features should be marked ``# needs sage.libs.pari``.
480+
SageMath uses the :ref:`PARI <spkg_pari>` library (via :ref:`cypari2
481+
<spkg_cypari>`) for numerous purposes. Doctests that involves such features
482+
should be marked ``# needs sage.libs.pari``.
428483
429-
In addition to the modularization purposes that this tag serves, it also provides attribution
430-
to the upstream project.
484+
In addition to the modularization purposes that this tag serves, it also
485+
provides attribution to the upstream project.
431486
432487
EXAMPLES::
433488
@@ -1005,6 +1060,8 @@ def all_features():
10051060
sage__libs__ecl(),
10061061
sage__libs__flint(),
10071062
sage__libs__gap(),
1063+
sage__libs__linbox(),
1064+
sage__libs__m4ri(),
10081065
sage__libs__ntl(),
10091066
sage__libs__pari(),
10101067
sage__libs__singular(),

src/sage/homology/homology_group.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ def HomologyGroup(n, base_ring, invfac=None):
165165
Multiplicative Abelian group isomorphic to Z x Z x Z x Z
166166
sage: HomologyGroup(4, ZZ)
167167
Z x Z x Z x Z
168+
169+
sage: # needs sage.libs.flint (otherwise timeout)
168170
sage: HomologyGroup(100, ZZ)
169171
Z^100
170172
"""

src/sage/matrix/action.pyx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,23 +209,23 @@ cdef class MatrixMatrixAction(MatrixMulAction):
209209
210210
Respects compatible subdivisions::
211211
212-
sage: M = matrix(5, 5, prime_range(100))
213-
sage: M.subdivide(2,3); M
212+
sage: M = matrix(5, 5, prime_range(100)) # needs sage.libs.pari
213+
sage: M.subdivide(2, 3); M # needs sage.libs.pari
214214
[ 2 3 5| 7 11]
215215
[13 17 19|23 29]
216216
[--------+-----]
217217
[31 37 41|43 47]
218218
[53 59 61|67 71]
219219
[73 79 83|89 97]
220-
sage: N = matrix(5,2,[n^2 for n in range(10)])
221-
sage: N.subdivide(3,1); N
220+
sage: N = matrix(5, 2, [n^2 for n in range(10)])
221+
sage: N.subdivide(3, 1); N
222222
[ 0| 1]
223223
[ 4| 9]
224224
[16|25]
225225
[--+--]
226226
[36|49]
227227
[64|81]
228-
sage: M*N
228+
sage: M*N # needs sage.libs.pari
229229
[ 1048| 1388]
230230
[ 3056| 4117]
231231
[-----+-----]
@@ -235,7 +235,7 @@ cdef class MatrixMatrixAction(MatrixMulAction):
235235
236236
Note that this is just like block matrix multiplication::
237237
238-
sage: M.subdivision(0,0) * N.subdivision(0,0) + M.subdivision(0,1) * N.subdivision(1,0)
238+
sage: M.subdivision(0,0) * N.subdivision(0,0) + M.subdivision(0,1) * N.subdivision(1,0) # needs sage.libs.pari
239239
[1048]
240240
[3056]
241241
@@ -249,7 +249,7 @@ cdef class MatrixMatrixAction(MatrixMulAction):
249249
[16|25]
250250
[36|49]
251251
[64|81]
252-
sage: M*N
252+
sage: M*N # needs sage.libs.pari
253253
[ 1048 1388]
254254
[ 3056 4117]
255255
[ 5360 7303]

src/sage/matrix/args.pyx

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ cdef class SparseEntry:
8383
sage: from sage.matrix.args import SparseEntry
8484
sage: SparseEntry(123, 456, "abc")
8585
SparseEntry(123, 456, 'abc')
86-
sage: SparseEntry(1/3, 2/3, x)
86+
sage: SparseEntry(1/3, 2/3, x) # needs sage.symbolic
8787
Traceback (most recent call last):
8888
...
8989
TypeError: unable to convert rational 1/3 to an integer
@@ -176,8 +176,10 @@ cdef class MatrixArgs:
176176
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Real Double Field; typ=SCALAR; entries=3.141592653589793>
177177
[3.141592653589793 0.0]
178178
[ 0.0 3.141592653589793]
179-
sage: ma = MatrixArgs(2, 2, entries=pi); ma.finalized(); ma.matrix()
180-
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Symbolic Ring; typ=SCALAR; entries=pi>
179+
sage: ma = MatrixArgs(2, 2, entries=pi); ma.finalized() # needs sage.symbolic
180+
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices
181+
over Symbolic Ring; typ=SCALAR; entries=pi>
182+
sage: ma.matrix() # needs sage.symbolic
181183
[pi 0]
182184
[ 0 pi]
183185
sage: ma = MatrixArgs(ZZ, 2, 2, entries={(0,0):7}); ma.finalized(); ma.matrix()
@@ -192,18 +194,27 @@ cdef class MatrixArgs:
192194
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Integer Ring; typ=SEQ_FLAT; entries=(1, 2, 3, 4)>
193195
[1 2]
194196
[3 4]
195-
sage: ma = MatrixArgs(QQ, entries=pari("[1,2;3,4]")); ma.finalized(); ma.matrix()
196-
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Rational Field; typ=SEQ_FLAT; entries=[1, 2, 3, 4]>
197+
198+
sage: # needs sage.libs.pari
199+
sage: ma = MatrixArgs(QQ, entries=pari("[1,2;3,4]")); ma.finalized()
200+
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices
201+
over Rational Field; typ=SEQ_FLAT; entries=[1, 2, 3, 4]>
202+
sage: ma.matrix()
197203
[1 2]
198204
[3 4]
199-
sage: ma = MatrixArgs(QQ, 2, 2, entries=pari("[1,2,3,4]")); ma.finalized(); ma.matrix()
200-
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Rational Field; typ=SEQ_FLAT; entries=[1, 2, 3, 4]>
205+
sage: ma = MatrixArgs(QQ, 2, 2, entries=pari("[1,2,3,4]")); ma.finalized()
206+
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices
207+
over Rational Field; typ=SEQ_FLAT; entries=[1, 2, 3, 4]>
208+
sage: ma.matrix()
201209
[1 2]
202210
[3 4]
203-
sage: ma = MatrixArgs(QQ, 2, 2, entries=pari("3/5")); ma.finalized(); ma.matrix()
204-
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Rational Field; typ=SCALAR; entries=3/5>
211+
sage: ma = MatrixArgs(QQ, 2, 2, entries=pari("3/5")); ma.finalized()
212+
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices
213+
over Rational Field; typ=SCALAR; entries=3/5>
214+
sage: ma.matrix()
205215
[3/5 0]
206216
[ 0 3/5]
217+
207218
sage: ma = MatrixArgs(entries=matrix(2,2)); ma.finalized(); ma.matrix()
208219
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Integer Ring; typ=MATRIX; entries=[0 0]
209220
[0 0]>
@@ -217,26 +228,37 @@ cdef class MatrixArgs:
217228
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Integer Ring; typ=CALLABLE; entries=<function ...>>
218229
[1 2]
219230
[3 4]
231+
232+
sage: # needs numpy
220233
sage: from numpy import array
221-
sage: ma = MatrixArgs(array([[1,2],[3,4]])); ma.finalized(); ma.matrix()
222-
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Integer Ring; typ=SEQ_SEQ; entries=array([[1, 2],
223-
[3, 4]])>
234+
sage: ma = MatrixArgs(array([[1,2],[3,4]])); ma.finalized()
235+
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices
236+
over Integer Ring; typ=SEQ_SEQ; entries=array([[1, 2], [3, 4]])>
237+
sage: ma.matrix()
224238
[1 2]
225239
[3 4]
226-
sage: ma = MatrixArgs(array([[1.,2.],[3.,4.]])); ma.finalized(); ma.matrix()
227-
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Real Double Field; typ=MATRIX; entries=[1.0 2.0]
228-
[3.0 4.0]>
240+
sage: ma = MatrixArgs(array([[1.,2.],[3.,4.]])); ma.finalized()
241+
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices
242+
over Real Double Field; typ=MATRIX; entries=[1.0 2.0]
243+
[3.0 4.0]>
244+
sage: ma.matrix()
229245
[1.0 2.0]
230246
[3.0 4.0]
231-
sage: ma = MatrixArgs(RealField(20), array([[1.,2.],[3.,4.]])); ma.finalized(); ma.matrix()
232-
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Real Field with 20 bits of precision; typ=MATRIX; entries=[1.0 2.0]
233-
[3.0 4.0]>
247+
sage: ma = MatrixArgs(RealField(20), array([[1.,2.],[3.,4.]])); ma.finalized()
248+
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Real Field
249+
with 20 bits of precision; typ=MATRIX; entries=[1.0 2.0]
250+
[3.0 4.0]>
251+
sage: ma.matrix()
234252
[1.0000 2.0000]
235253
[3.0000 4.0000]
236-
sage: ma = MatrixArgs(graphs.CycleGraph(3)); ma.finalized(); ma.matrix()
237-
<MatrixArgs for Full MatrixSpace of 3 by 3 dense matrices over Integer Ring; typ=MATRIX; entries=[0 1 1]
238-
[1 0 1]
239-
[1 1 0]>
254+
255+
sage: # needs sage.graphs
256+
sage: ma = MatrixArgs(graphs.CycleGraph(3)); ma.finalized()
257+
<MatrixArgs for Full MatrixSpace of 3 by 3 dense matrices
258+
over Integer Ring; typ=MATRIX; entries=[0 1 1]
259+
[1 0 1]
260+
[1 1 0]>
261+
sage: ma.matrix()
240262
[0 1 1]
241263
[1 0 1]
242264
[1 1 0]
@@ -458,8 +480,8 @@ cdef class MatrixArgs:
458480
459481
Sparse examples::
460482
461-
sage: ma = MatrixArgs(3, 3, pi)
462-
sage: list(ma.iter(sparse=True))
483+
sage: ma = MatrixArgs(3, 3, pi) # needs sage.symbolic
484+
sage: list(ma.iter(sparse=True)) # needs sage.symbolic
463485
[SparseEntry(0, 0, pi), SparseEntry(1, 1, pi), SparseEntry(2, 2, pi)]
464486
sage: ma = MatrixArgs(2, 3)
465487
sage: list(ma.iter(sparse=True))
@@ -819,11 +841,11 @@ cdef class MatrixArgs:
819841
EXAMPLES::
820842
821843
sage: from sage.matrix.args import MatrixArgs
822-
sage: MatrixArgs(pi).finalized()
844+
sage: MatrixArgs(pi).finalized() # needs sage.symbolic
823845
Traceback (most recent call last):
824846
...
825847
TypeError: the dimensions of the matrix must be specified
826-
sage: MatrixArgs(RR, pi).finalized()
848+
sage: MatrixArgs(RR, pi).finalized() # needs sage.symbolic
827849
Traceback (most recent call last):
828850
...
829851
TypeError: the dimensions of the matrix must be specified
@@ -1222,6 +1244,7 @@ cdef class MatrixArgs:
12221244
12231245
Check that :trac:`26655` is fixed::
12241246
1247+
sage: # needs sage.rings.finite_rings
12251248
sage: F.<a> = GF(9)
12261249
sage: M = MatrixSpace(F, 2, 2)
12271250
sage: A = M([[1, a], [0, 1]])
@@ -1232,11 +1255,11 @@ cdef class MatrixArgs:
12321255
Constructing a matrix from a PARI ``t_VEC`` or ``t_COL`` with
12331256
``t_VEC`` or ``t_COL`` elements is currently not supported::
12341257
1235-
sage: M(pari([1, a, 0, 1]))
1258+
sage: M(pari([1, a, 0, 1])) # needs sage.libs.pari sage.rings.finite_rings
12361259
Traceback (most recent call last):
12371260
...
12381261
NameError: name 'a' is not defined
1239-
sage: M(pari([[1, a], [0, 1]]))
1262+
sage: M(pari([[1, a], [0, 1]])) # needs sage.libs.pari sage.rings.finite_rings
12401263
Traceback (most recent call last):
12411264
...
12421265
NameError: name 'a' is not defined
@@ -1351,7 +1374,7 @@ cpdef MatrixArgs MatrixArgs_init(space, entries):
13511374
13521375
sage: from sage.matrix.args import MatrixArgs_init
13531376
sage: S = MatrixSpace(GF(2), 2, 4)
1354-
sage: ma = MatrixArgs_init(S, {(1,3):7})
1377+
sage: ma = MatrixArgs_init(S, {(1, 3): 7})
13551378
sage: M = ma.matrix(); M
13561379
[0 0 0 0]
13571380
[0 0 0 1]

src/sage/matrix/benchmark.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# sage.doctest: needs sage.flint
12
"""
23
Benchmarks for matrices
34
@@ -18,13 +19,14 @@
1819
"""
1920

2021
from .constructor import random_matrix, Matrix
22+
from sage.misc.lazy_import import lazy_import
2123
from sage.rings.integer_ring import ZZ
2224
from sage.rings.rational_field import QQ
2325
from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF
2426
from sage.misc.timing import cputime
2527
from cysignals.alarm import AlarmInterrupt, alarm, cancel_alarm
2628

27-
from sage.interfaces.magma import magma
29+
lazy_import('sage.interfaces.magma', 'magma')
2830

2931
verbose = False
3032

src/sage/matrix/berlekamp_massey.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ def berlekamp_massey(a):
5555
sage: from sage.matrix.berlekamp_massey import berlekamp_massey
5656
sage: berlekamp_massey([1,2,1,2,1,2])
5757
x^2 - 1
58-
sage: berlekamp_massey([GF(7)(1),19,1,19])
58+
sage: berlekamp_massey([GF(7)(1), 19, 1, 19])
5959
x^2 + 6
6060
sage: berlekamp_massey([2,2,1,2,1,191,393,132])
6161
x^4 - 36727/11711*x^3 + 34213/5019*x^2 + 7024942/35133*x - 335813/1673
62-
sage: berlekamp_massey(prime_range(2,38))
62+
sage: berlekamp_massey(prime_range(2, 38)) # needs sage.libs.pari
6363
x^6 - 14/9*x^5 - 7/9*x^4 + 157/54*x^3 - 25/27*x^2 - 73/18*x + 37/9
6464
6565
TESTS::

src/sage/matrix/compute_J_ideal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# sage.doctest: needs sage.libs.pari (for charpoly, minimal_polynomial in __init__)
12
r"""
23
`J`-ideals of matrices
34

0 commit comments

Comments
 (0)