Skip to content

Commit

Permalink
src/sage/matrix/{args,constructor}.pyx: Docstring cosmetics
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Mar 5, 2024
1 parent d626e4b commit 2b8f034
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
29 changes: 18 additions & 11 deletions src/sage/matrix/args.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -313,21 +313,27 @@ cdef class MatrixArgs:
sage: from sage.matrix.args import MatrixArgs
sage: MatrixArgs().finalized()
<MatrixArgs for Full MatrixSpace of 0 by 0 dense matrices over Integer Ring; typ=ZERO; entries=None>
<MatrixArgs for Full MatrixSpace of 0 by 0 dense matrices over
Integer Ring; typ=ZERO; entries=None>
sage: MatrixArgs(1).finalized()
<MatrixArgs for Full MatrixSpace of 1 by 1 dense matrices over Integer Ring; typ=ZERO; entries=None>
<MatrixArgs for Full MatrixSpace of 1 by 1 dense matrices over
Integer Ring; typ=ZERO; entries=None>
sage: MatrixArgs(1, 1, 3).finalized()
<MatrixArgs for Full MatrixSpace of 1 by 1 dense matrices over Integer Ring; typ=SCALAR; entries=3>
<MatrixArgs for Full MatrixSpace of 1 by 1 dense matrices over
Integer Ring; typ=SCALAR; entries=3>
sage: MatrixArgs(1, 1, 1, 1).finalized()
Traceback (most recent call last):
...
TypeError: too many arguments in matrix constructor
sage: MatrixArgs(3, nrows=1, ncols=1).finalized()
<MatrixArgs for Full MatrixSpace of 1 by 1 dense matrices over Integer Ring; typ=SCALAR; entries=3>
<MatrixArgs for Full MatrixSpace of 1 by 1 dense matrices over
Integer Ring; typ=SCALAR; entries=3>
sage: MatrixArgs(3, nrows=1).finalized()
<MatrixArgs for Full MatrixSpace of 1 by 1 dense matrices over Integer Ring; typ=SCALAR; entries=3>
<MatrixArgs for Full MatrixSpace of 1 by 1 dense matrices over
Integer Ring; typ=SCALAR; entries=3>
sage: MatrixArgs(3, ncols=1).finalized()
<MatrixArgs for Full MatrixSpace of 1 by 1 dense matrices over Integer Ring; typ=SCALAR; entries=3>
<MatrixArgs for Full MatrixSpace of 1 by 1 dense matrices over
Integer Ring; typ=SCALAR; entries=3>
"""
self.base = ring
if nrows is not None:
Expand Down Expand Up @@ -719,7 +725,7 @@ cdef class MatrixArgs:
INPUT:
- ``convert`` -- If True, the entries are converted to the base
- ``convert`` -- If ``True``, the entries are converted to the base
ring. Otherwise, the entries are returned as given.
.. NOTE::
Expand Down Expand Up @@ -779,11 +785,12 @@ cdef class MatrixArgs:

cpdef dict dict(self, bint convert=True) noexcept:
"""
Return the entries of the matrix as a dict. The keys of this
dict are the non-zero positions ``(i,j)``. The corresponding
value is the entry at that position. Zero values are skipped.
Return the entries of the matrix as a :class:`dict`.
If ``convert`` is True, the entries are converted to the base
The keys of this :class:`dict` are the non-zero positions ``(i,j)``. The
corresponding value is the entry at that position. Zero values are skipped.
If ``convert`` is ``True``, the entries are converted to the base
ring. Otherwise, the entries are returned as given.
EXAMPLES::
Expand Down
24 changes: 12 additions & 12 deletions src/sage/matrix/constructor.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def matrix(*args, **kwds):
INPUT:
The matrix command takes the entries of a matrix, optionally
The :func:`matrix` command takes the entries of a matrix, optionally
preceded by a ring and the dimensions of the matrix, and returns a
matrix.
Expand All @@ -49,11 +49,11 @@ def matrix(*args, **kwds):
columns. You can create a matrix of zeros by passing an empty list
or the integer zero for the entries. To construct a multiple of
the identity (`cI`), you can specify square dimensions and pass in
`c`. Calling matrix() with a Sage object may return something that
makes sense. Calling matrix() with a NumPy array will convert the
`c`. Calling :func:`matrix` with a Sage object may return something that
makes sense. Calling :func:`matrix` with a NumPy array will convert the
array to a matrix.
All arguments (even the positional) are optional.
All arguments (even the positional ones) are optional.
Positional and keyword arguments:
Expand Down Expand Up @@ -105,7 +105,7 @@ def matrix(*args, **kwds):
::
sage: m = matrix(QQ,[[1,2,3],[4,5,6]]); m; m.parent()
sage: m = matrix(QQ, [[1,2,3],[4,5,6]]); m; m.parent()
[1 2 3]
[4 5 6]
Full MatrixSpace of 2 by 3 dense matrices over Rational Field
Expand Down Expand Up @@ -135,37 +135,37 @@ def matrix(*args, **kwds):
::
sage: v1=vector((1,2,3))
sage: v2=vector((4,5,6))
sage: v1 = vector((1,2,3))
sage: v2 = vector((4,5,6))
sage: m = matrix([v1,v2]); m; m.parent()
[1 2 3]
[4 5 6]
Full MatrixSpace of 2 by 3 dense matrices over Integer Ring
::
sage: m = matrix(QQ,2,[1,2,3,4,5,6]); m; m.parent()
sage: m = matrix(QQ, 2, [1,2,3,4,5,6]); m; m.parent()
[1 2 3]
[4 5 6]
Full MatrixSpace of 2 by 3 dense matrices over Rational Field
::
sage: m = matrix(QQ,2,3,[1,2,3,4,5,6]); m; m.parent()
sage: m = matrix(QQ, 2, 3, [1,2,3,4,5,6]); m; m.parent()
[1 2 3]
[4 5 6]
Full MatrixSpace of 2 by 3 dense matrices over Rational Field
::
sage: m = matrix({(0,1): 2, (1,1):2/5}); m; m.parent()
sage: m = matrix({(0,1): 2, (1,1): 2/5}); m; m.parent()
[ 0 2]
[ 0 2/5]
Full MatrixSpace of 2 by 2 sparse matrices over Rational Field
::
sage: m = matrix(QQ,2,3,{(1,1): 2}); m; m.parent()
sage: m = matrix(QQ, 2, 3, {(1,1): 2}); m; m.parent()
[0 0 0]
[0 2 0]
Full MatrixSpace of 2 by 3 sparse matrices over Rational Field
Expand Down Expand Up @@ -234,7 +234,7 @@ def matrix(*args, **kwds):
::
sage: M = Matrix([[1,2,3],[4,5,6],[7,8,9]], immutable=True)
sage: M = Matrix([[1,2,3], [4,5,6], [7,8,9]], immutable=True)
sage: M[0] = [9,9,9]
Traceback (most recent call last):
...
Expand Down

0 comments on commit 2b8f034

Please sign in to comment.