Skip to content
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

src/sage/matrix: Doctest cosmetics #37607

Merged
merged 2 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
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
35 changes: 25 additions & 10 deletions src/sage/matrix/action.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ Actions used by the coercion model for matrix and vector multiplications
sage: MSZ = MatrixSpace(ZZ['x'], 2)
sage: A = MSQ.get_action(MSZ)
sage: A
Left action by Full MatrixSpace of 2 by 2 dense matrices over Rational Field on Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring
Left action by Full MatrixSpace of 2 by 2 dense matrices over Rational Field
on Full MatrixSpace of 2 by 2 dense matrices
over Univariate Polynomial Ring in x over Integer Ring
sage: import gc
sage: _ = gc.collect()
sage: A
Left action by Full MatrixSpace of 2 by 2 dense matrices over Rational Field on Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring
Left action by Full MatrixSpace of 2 by 2 dense matrices over Rational Field
on Full MatrixSpace of 2 by 2 dense matrices
over Univariate Polynomial Ring in x over Integer Ring

.. NOTE::

Expand Down Expand Up @@ -83,13 +87,17 @@ cdef class MatrixMulAction(Action):
sage: MSQ = MatrixSpace(QQ, 2)
sage: MSZ = MatrixSpace(ZZ['x'], 2)
sage: A = MSQ.get_action(MSZ); A
Left action by Full MatrixSpace of 2 by 2 dense matrices over Rational Field on Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring
Left action by Full MatrixSpace of 2 by 2 dense matrices over Rational Field
on Full MatrixSpace of 2 by 2 dense matrices
over Univariate Polynomial Ring in x over Integer Ring
sage: A.actor()
Full MatrixSpace of 2 by 2 dense matrices over Rational Field
sage: A.domain()
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring
Full MatrixSpace of 2 by 2 dense matrices
over Univariate Polynomial Ring in x over Integer Ring
sage: A.codomain()
Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field
Full MatrixSpace of 2 by 2 dense matrices
over Univariate Polynomial Ring in x over Rational Field
"""
def __init__(self, G, S, is_left):
if not is_MatrixSpace(G):
Expand Down Expand Up @@ -130,9 +138,13 @@ cdef class MatrixMatrixAction(MatrixMulAction):
sage: MSQ = MatrixSpace(QQ, 3, 2)
sage: from sage.matrix.action import MatrixMatrixAction
sage: A = MatrixMatrixAction(MSR, MSQ); A
Left action by Full MatrixSpace of 3 by 3 dense matrices over Univariate Polynomial Ring in x over Integer Ring on Full MatrixSpace of 3 by 2 dense matrices over Rational Field
Left action
by Full MatrixSpace of 3 by 3 dense matrices
over Univariate Polynomial Ring in x over Integer Ring
on Full MatrixSpace of 3 by 2 dense matrices over Rational Field
sage: A.codomain()
Full MatrixSpace of 3 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field
Full MatrixSpace of 3 by 2 dense matrices
over Univariate Polynomial Ring in x over Rational Field
sage: A(matrix(R, 3, 3, x), matrix(QQ, 3, 2, range(6)))
[ 0 x]
[2*x 3*x]
Expand Down Expand Up @@ -183,7 +195,8 @@ cdef class MatrixMatrixAction(MatrixMulAction):
sage: MSR = MatrixSpace(R, 3, 3)
sage: MSQ = MatrixSpace(QQ, 3, 2)
sage: A = MatrixMatrixAction(MSR, MSQ); A
Left action by Full MatrixSpace of 3 by 3 dense matrices over Univariate Polynomial Ring in x over Integer Ring on Full MatrixSpace of 3 by 2 dense matrices over Rational Field
Left action by Full MatrixSpace of 3 by 3 dense matrices over Univariate Polynomial Ring in x over Integer Ring
on Full MatrixSpace of 3 by 2 dense matrices over Rational Field
sage: A.codomain()
Full MatrixSpace of 3 by 2 dense matrices over Univariate Polynomial Ring in x over Rational Field

Expand Down Expand Up @@ -303,7 +316,8 @@ cdef class MatrixVectorAction(MatrixMulAction):
sage: M = MatrixSpace(QQ, 5, 3)
sage: V = VectorSpace(CDF, 3) # strong reference prevents garbage collection
sage: A = MatrixVectorAction(M, V); A
Left action by Full MatrixSpace of 5 by 3 dense matrices over Rational Field on Vector space of dimension 3 over Complex Double Field
Left action by Full MatrixSpace of 5 by 3 dense matrices over Rational Field
on Vector space of dimension 3 over Complex Double Field
sage: A.codomain()
Vector space of dimension 5 over Complex Double Field
"""
Expand Down Expand Up @@ -354,7 +368,8 @@ cdef class VectorMatrixAction(MatrixMulAction):
sage: V = VectorSpace(CDF, 3)
sage: A = VectorMatrixAction(M, V)
sage: A
Right action by Full MatrixSpace of 3 by 5 dense matrices over Rational Field on Vector space of dimension 3 over Complex Double Field
Right action by Full MatrixSpace of 3 by 5 dense matrices over Rational Field
on Vector space of dimension 3 over Complex Double Field
sage: A.codomain()
Vector space of dimension 5 over Complex Double Field
"""
Expand Down
109 changes: 70 additions & 39 deletions src/sage/matrix/args.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,33 @@ cdef class MatrixArgs:
sage: ma = MatrixArgs(2, 2, (x for x in range(4))); ma
<MatrixArgs for None; typ=UNKNOWN; entries=<generator ...>>
sage: ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Integer Ring; typ=SEQ_FLAT; entries=[0, 1, 2, 3]>
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices
over Integer Ring; typ=SEQ_FLAT; entries=[0, 1, 2, 3]>

Many types of input are possible::

sage: ma = MatrixArgs(2, 2, entries=None); ma.finalized(); ma.matrix()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Integer Ring; typ=ZERO; entries=None>
sage: ma = MatrixArgs(2, 2, entries=None); ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices
over Integer Ring; typ=ZERO; entries=None>
sage: ma.matrix()
[0 0]
[0 0]
sage: ma = MatrixArgs(2, 2, entries={}); ma.finalized(); ma.matrix()
<MatrixArgs for Full MatrixSpace of 2 by 2 sparse matrices over Integer Ring; typ=SEQ_SPARSE; entries=[]>
sage: ma = MatrixArgs(2, 2, entries={}); ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 2 sparse matrices
over Integer Ring; typ=SEQ_SPARSE; entries=[]>
sage: ma.matrix()
[0 0]
[0 0]
sage: ma = MatrixArgs(2, 2, entries=[1,2,3,4]); ma.finalized(); ma.matrix()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Integer Ring; typ=SEQ_FLAT; entries=[1, 2, 3, 4]>
sage: ma = MatrixArgs(2, 2, entries=[1,2,3,4]); ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices
over Integer Ring; typ=SEQ_FLAT; entries=[1, 2, 3, 4]>
sage: ma.matrix()
[1 2]
[3 4]
sage: ma = MatrixArgs(2, 2, entries=math.pi); ma.finalized(); ma.matrix()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Real Double Field; typ=SCALAR; entries=3.141592653589793>
sage: ma = MatrixArgs(2, 2, entries=math.pi); ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices
over Real Double Field; typ=SCALAR; entries=3.141592653589793>
sage: ma.matrix()
[3.141592653589793 0.0]
[ 0.0 3.141592653589793]
sage: ma = MatrixArgs(2, 2, entries=pi); ma.finalized() # needs sage.symbolic
Expand All @@ -182,16 +191,22 @@ cdef class MatrixArgs:
sage: ma.matrix() # needs sage.symbolic
[pi 0]
[ 0 pi]
sage: ma = MatrixArgs(ZZ, 2, 2, entries={(0,0):7}); ma.finalized(); ma.matrix()
<MatrixArgs for Full MatrixSpace of 2 by 2 sparse matrices over Integer Ring; typ=SEQ_SPARSE; entries=[SparseEntry(0, 0, 7)]>
sage: ma = MatrixArgs(ZZ, 2, 2, entries={(0,0): 7}); ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 2 sparse matrices
over Integer Ring; typ=SEQ_SPARSE; entries=[SparseEntry(0, 0, 7)]>
sage: ma.matrix()
[7 0]
[0 0]
sage: ma = MatrixArgs(ZZ, 2, 2, entries=((1,2),(3,4))); ma.finalized(); ma.matrix()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Integer Ring; typ=SEQ_SEQ; entries=((1, 2), (3, 4))>
sage: ma = MatrixArgs(ZZ, 2, 2, entries=((1,2), (3,4))); ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices
over Integer Ring; typ=SEQ_SEQ; entries=((1, 2), (3, 4))>
sage: ma.matrix()
[1 2]
[3 4]
sage: ma = MatrixArgs(ZZ, 2, 2, entries=(1,2,3,4)); ma.finalized(); ma.matrix()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Integer Ring; typ=SEQ_FLAT; entries=(1, 2, 3, 4)>
sage: ma = MatrixArgs(ZZ, 2, 2, entries=(1,2,3,4)); ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices
over Integer Ring; typ=SEQ_FLAT; entries=(1, 2, 3, 4)>
sage: ma.matrix()
[1 2]
[3 4]

Expand All @@ -215,17 +230,23 @@ cdef class MatrixArgs:
[3/5 0]
[ 0 3/5]

sage: ma = MatrixArgs(entries=matrix(2,2)); ma.finalized(); ma.matrix()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Integer Ring; typ=MATRIX; entries=[0 0]
[0 0]>
sage: ma = MatrixArgs(entries=matrix(2,2)); ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices
over Integer Ring; typ=MATRIX; entries=[0 0]
[0 0]>
sage: ma.matrix()
[0 0]
[0 0]
sage: ma = MatrixArgs(2, 2, entries=lambda i,j: 1+2*i+j); ma.finalized(); ma.matrix()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Integer Ring; typ=SEQ_FLAT; entries=[1, 2, 3, 4]>
sage: ma = MatrixArgs(2, 2, entries=lambda i,j: 1+2*i+j); ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices
over Integer Ring; typ=SEQ_FLAT; entries=[1, 2, 3, 4]>
sage: ma.matrix()
[1 2]
[3 4]
sage: ma = MatrixArgs(ZZ, 2, 2, entries=lambda i,j: 1+2*i+j); ma.finalized(); ma.matrix()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Integer Ring; typ=CALLABLE; entries=<function ...>>
sage: ma = MatrixArgs(ZZ, 2, 2, entries=lambda i,j: 1+2*i+j); ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices
over Integer Ring; typ=CALLABLE; entries=<function ...>>
sage: ma.matrix()
[1 2]
[3 4]

Expand Down Expand Up @@ -263,9 +284,12 @@ cdef class MatrixArgs:
[1 0 1]
[1 1 0]

sage: ma = MatrixArgs([vector([0,1], sparse=True), vector([0,0], sparse=True)], sparse=True)
sage: ma.finalized(); ma.matrix()
<MatrixArgs for Full MatrixSpace of 2 by 2 sparse matrices over Integer Ring; typ=SEQ_SPARSE; entries=[SparseEntry(0, 1, 1)]>
sage: ma = MatrixArgs([vector([0,1], sparse=True),
....: vector([0,0], sparse=True)], sparse=True)
sage: ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 2 sparse matrices over
Integer Ring; typ=SEQ_SPARSE; entries=[SparseEntry(0, 1, 1)]>
sage: ma.matrix()
[0 1]
[0 0]

Expand Down Expand Up @@ -633,7 +657,8 @@ cdef class MatrixArgs:
::

sage: ma = MatrixArgs(M); ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 3 sparse matrices over Integer Ring; typ=MATRIX; entries=[0 1 2]
<MatrixArgs for Full MatrixSpace of 2 by 3 sparse matrices
over Integer Ring; typ=MATRIX; entries=[0 1 2]
[3 4 5]>
sage: ma.matrix()
[0 1 2]
Expand All @@ -642,17 +667,19 @@ cdef class MatrixArgs:
::

sage: ma = MatrixArgs(M, sparse=False); ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 3 dense matrices over Integer Ring; typ=MATRIX; entries=[0 1 2]
[3 4 5]>
<MatrixArgs for Full MatrixSpace of 2 by 3 dense matrices
over Integer Ring; typ=MATRIX; entries=[0 1 2]
[3 4 5]>
sage: ma.matrix()
[0 1 2]
[3 4 5]

::

sage: ma = MatrixArgs(RDF, M); ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 3 sparse matrices over Real Double Field; typ=MATRIX; entries=[0 1 2]
[3 4 5]>
<MatrixArgs for Full MatrixSpace of 2 by 3 sparse matrices
over Real Double Field; typ=MATRIX; entries=[0 1 2]
[3 4 5]>
sage: ma.matrix(convert=False)
[0 1 2]
[3 4 5]
Expand Down Expand Up @@ -810,7 +837,8 @@ cdef class MatrixArgs:
sage: S = MatrixSpace(QQ, 3, 2, sparse=True)
sage: _ = ma.set_space(S)
sage: ma.finalized()
<MatrixArgs for Full MatrixSpace of 3 by 2 sparse matrices over Rational Field; typ=ZERO; entries=None>
<MatrixArgs for Full MatrixSpace of 3 by 2 sparse matrices
over Rational Field; typ=ZERO; entries=None>
sage: M = ma.matrix(); M
[0 0]
[0 0]
Expand Down Expand Up @@ -848,7 +876,8 @@ cdef class MatrixArgs:
...
TypeError: the dimensions of the matrix must be specified
sage: MatrixArgs(2, 3, 0.0).finalized()
<MatrixArgs for Full MatrixSpace of 2 by 3 dense matrices over Real Field with 53 bits of precision; typ=ZERO; entries=0.000000000000000>
<MatrixArgs for Full MatrixSpace of 2 by 3 dense matrices over Real
Field with 53 bits of precision; typ=ZERO; entries=0.000000000000000>
sage: MatrixArgs(RR, 2, 3, 1.0).finalized()
Traceback (most recent call last):
...
Expand Down Expand Up @@ -1020,19 +1049,21 @@ cdef class MatrixArgs:
EXAMPLES::

sage: from sage.matrix.args import MatrixArgs
sage: ma = MatrixArgs({(2,5):1/2, (4,-3):1/3})
sage: ma = MatrixArgs(2, 2, {(-1,0):2, (0,-1):1}, sparse=True)
sage: ma = MatrixArgs({(2,5): 1/2, (4,-3): 1/3})
sage: ma = MatrixArgs(2, 2, {(-1,0): 2, (0,-1): 1}, sparse=True)
sage: ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 2 sparse matrices over Integer Ring; typ=SEQ_SPARSE; entries=[SparseEntry(...), SparseEntry(...)]>
sage: ma = MatrixArgs(2, 2, {(-1,0):2, (0,-1):1}, sparse=False)
<MatrixArgs for Full MatrixSpace of 2 by 2 sparse matrices over
Integer Ring; typ=SEQ_SPARSE; entries=[SparseEntry(...), SparseEntry(...)]>
sage: ma = MatrixArgs(2, 2, {(-1,0): 2, (0,-1): 1}, sparse=False)
sage: ma.finalized()
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over Integer Ring; typ=SEQ_FLAT; entries=[0, 1, 2, 0]>
sage: ma = MatrixArgs(2, 1, {(1,0):88, (0,1):89})
<MatrixArgs for Full MatrixSpace of 2 by 2 dense matrices over
Integer Ring; typ=SEQ_FLAT; entries=[0, 1, 2, 0]>
sage: ma = MatrixArgs(2, 1, {(1,0): 88, (0,1): 89})
sage: ma.finalized()
Traceback (most recent call last):
...
IndexError: invalid column index 1
sage: ma = MatrixArgs(1, 2, {(1,0):88, (0,1):89})
sage: ma = MatrixArgs(1, 2, {(1,0): 88, (0,1): 89})
sage: ma.finalized()
Traceback (most recent call last):
...
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matrix/compute_J_ideal.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,8 @@ def mccoy_column(self, p, t, nu):
sage: x = polygen(ZZ, 'x')
sage: nu_4 = x^2 + 3*x + 2
sage: g = C.mccoy_column(2, 2, nu_4)
sage: b = matrix(9, 1, (x-B).adjugate().list())
sage: M = matrix.block([[b , -B.charpoly(x)*matrix.identity(9)]])
sage: b = matrix(9, 1, (x - B).adjugate().list())
sage: M = matrix.block([[b, -B.charpoly(x)*matrix.identity(9)]])
sage: (M*g % 4).is_zero()
True

Expand Down
Loading
Loading