Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 081643c

Browse files
committed
29243: fix details
1 parent b2f0433 commit 081643c

File tree

3 files changed

+72
-12
lines changed

3 files changed

+72
-12
lines changed

src/sage/matrix/matrix2.pyx

+11-4
Original file line numberDiff line numberDiff line change
@@ -6038,13 +6038,16 @@ cdef class Matrix(Matrix1):
60386038
self.cache('eigenvalues', eigenvalues)
60396039
return eigenvalues
60406040

6041-
def eigenvectors_left(self, other=None, extend=True):
6041+
def eigenvectors_left(self, other=None, *, extend=True):
60426042
r"""
60436043
Compute the left eigenvectors of a matrix.
60446044

60456045
INPUT:
60466046

6047-
- ``other`` -- not supported
6047+
- ``other`` -- a square matrix `B` (default: ``None``) in a generalized
6048+
eigenvalue problem; if ``None``, an ordinary eigenvalue problem is
6049+
solved (currently supported only if the base ring of ``self`` is
6050+
``RDF`` or ``CDF``)
60486051

60496052
- ``extend`` -- boolean (default: ``True``)
60506053

@@ -6117,6 +6120,7 @@ cdef class Matrix(Matrix1):
61176120
deprecation(29243,
61186121
'"extend" should be used as keyword argument')
61196122
extend = other
6123+
other = None
61206124
else:
61216125
raise NotImplementedError('generalized eigenvector '
61226126
'decomposition is implemented '
@@ -6162,13 +6166,16 @@ cdef class Matrix(Matrix1):
61626166

61636167
left_eigenvectors = eigenvectors_left
61646168

6165-
def eigenvectors_right(self, other=None, extend=True):
6169+
def eigenvectors_right(self, other=None, *, extend=True):
61666170
r"""
61676171
Compute the right eigenvectors of a matrix.
61686172

61696173
INPUT:
61706174

6171-
- ``other`` -- not supported
6175+
- ``other`` -- a square matrix `B` (default: ``None``) in a generalized
6176+
eigenvalue problem; if ``None``, an ordinary eigenvalue problem is
6177+
solved (currently supported only if the base ring of ``self`` is
6178+
``RDF`` or ``CDF``)
61726179

61736180
- ``extend`` -- boolean (default: ``True``)
61746181

src/sage/matrix/matrix_double_dense.pyx

+43-8
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ cdef class Matrix_double_dense(Matrix_dense):
12041204
self.cache('PLU_factors', PLU)
12051205
return PLU
12061206

1207-
def eigenvalues(self, other=None, algorithm='default', tol=None,
1207+
def eigenvalues(self, other=None, algorithm='default', tol=None, *,
12081208
homogeneous=False):
12091209
r"""
12101210
Return a list of ordinary or generalized eigenvalues.
@@ -1380,6 +1380,10 @@ cdef class Matrix_double_dense(Matrix_dense):
13801380
Traceback (most recent call last):
13811381
...
13821382
ValueError: matrix must be square, not 2 x 3
1383+
sage: matrix.identity(CDF, 2).eigenvalues(A)
1384+
Traceback (most recent call last):
1385+
...
1386+
ValueError: other matrix must be square, not 2 x 3
13831387
13841388
sage: A = matrix(CDF, 2, [1, 2, 3, 4*I])
13851389
sage: A.eigenvalues(algorithm='symmetric')
@@ -1411,21 +1415,52 @@ cdef class Matrix_double_dense(Matrix_dense):
14111415
sage: B = matrix(CDF, [[2, 1+I], [1-I, 3]])
14121416
sage: A.eigenvalues(B, algorithm='hermitian', homogeneous=True) # tol 1e-14
14131417
[(0.25, 1.0), (1.0, 1.0)]
1418+
1419+
Test the deprecation::
1420+
1421+
sage: A = graphs.PetersenGraph().adjacency_matrix().change_ring(RDF)
1422+
sage: ev = A.eigenvalues('symmetric', 1e-13)
1423+
doctest:...: DeprecationWarning: "extend" and "tol" should be used
1424+
as keyword argument only
1425+
See https://trac.sagemath.org/29243 for details.
1426+
sage: ev # tol 1e-13
1427+
[(-2.0, 4), (1.0, 5), (3.0, 1)]
1428+
sage: A.eigenvalues('symmetric', 1e-13, tol=1e-12)
1429+
Traceback (most recent call last):
1430+
...
1431+
TypeError: eigenvalues() got multiple values for keyword argument 'tol'
1432+
sage: A.eigenvalues('symmetric', algorithm='hermitian')
1433+
Traceback (most recent call last):
1434+
...
1435+
TypeError: eigenvalues() got multiple values for keyword argument 'algorithm'
14141436
"""
14151437
from sage.rings.real_double import RDF
14161438
from sage.rings.complex_double import CDF
14171439
if isinstance(other, str):
14181440
# for backward compatibilty, allow algorithm to be passed as first
1419-
# positional argument
1441+
# positional argument and tol as second positional argument
1442+
from sage.misc.superseded import deprecation
1443+
deprecation(29243, '"extend" and "tol" should be used as '
1444+
'keyword argument only')
1445+
if algorithm != 'default':
1446+
if isinstance(algorithm, str):
1447+
raise TypeError("eigenvalues() got multiple values for "
1448+
"keyword argument 'algorithm'")
1449+
if tol is not None:
1450+
raise TypeError("eigenvalues() got multiple values for "
1451+
"keyword argument 'tol'")
1452+
tol = algorithm
14201453
algorithm = other
14211454
other = None
14221455
if not algorithm in ['default', 'symmetric', 'hermitian']:
14231456
msg = "algorithm must be 'default', 'symmetric', or 'hermitian', not {0}"
14241457
raise ValueError(msg.format(algorithm))
1425-
if not self.is_square() or other is not None and not other.is_square():
1426-
msg = 'matrix must be square, not {0} x {1}'
1427-
m = self if not self.is_square() else other
1428-
raise ValueError(msg.format(m.nrows(), m.ncols()))
1458+
if not self.is_square():
1459+
raise ValueError('matrix must be square, not %s x %s'
1460+
% (self.nrows(), self.ncols()))
1461+
if other is not None and not other.is_square():
1462+
raise ValueError('other matrix must be square, not %s x %s'
1463+
% (other.nrows(), other.ncols()))
14291464
if algorithm == 'symmetric':
14301465
if self.base_ring() != RDF:
14311466
try:
@@ -1503,7 +1538,7 @@ cdef class Matrix_double_dense(Matrix_dense):
15031538
ev_group[location][2] = ev_group[location][0]/ev_group[location][1]
15041539
return [(return_class(avg), m) for _, m, avg in ev_group]
15051540

1506-
def left_eigenvectors(self, other=None, homogeneous=False):
1541+
def left_eigenvectors(self, other=None, *, homogeneous=False):
15071542
r"""
15081543
Compute the ordinary or generalized left eigenvectors of a matrix of
15091544
double precision real or complex numbers (i.e. ``RDF`` or ``CDF``).
@@ -1661,7 +1696,7 @@ cdef class Matrix_double_dense(Matrix_dense):
16611696

16621697
eigenvectors_left = left_eigenvectors
16631698

1664-
def right_eigenvectors(self, other=None, homogeneous=False):
1699+
def right_eigenvectors(self, other=None, *, homogeneous=False):
16651700
r"""
16661701
Compute the ordinary or generalized right eigenvectors of a matrix of
16671702
double precision real or complex numbers (i.e. ``RDF`` or ``CDF``).

src/sage/matrix/matrix_symbolic_dense.pyx

+18
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ cdef class Matrix_symbolic_dense(Matrix_generic_dense):
187187
r"""
188188
Compute the left eigenvectors of a matrix.
189189
190+
INPUT:
191+
192+
- ``other`` -- a square matrix `B` (default: ``None``) in a generalized
193+
eigenvalue problem; if ``None``, an ordinary eigenvalue problem is
194+
solved (currently supported only if the base ring of ``self`` is
195+
``RDF`` or ``CDF``)
196+
197+
OUTPUT:
198+
190199
For each distinct eigenvalue, returns a list of the form (e,V,n)
191200
where e is the eigenvalue, V is a list of eigenvectors forming a
192201
basis for the corresponding left eigenspace, and n is the
@@ -286,6 +295,15 @@ cdef class Matrix_symbolic_dense(Matrix_generic_dense):
286295
r"""
287296
Compute the right eigenvectors of a matrix.
288297
298+
INPUT:
299+
300+
- ``other`` -- a square matrix `B` (default: ``None``) in a generalized
301+
eigenvalue problem; if ``None``, an ordinary eigenvalue problem is
302+
solved (currently supported only if the base ring of ``self`` is
303+
``RDF`` or ``CDF``)
304+
305+
OUTPUT:
306+
289307
For each distinct eigenvalue, returns a list of the form (e,V,n)
290308
where e is the eigenvalue, V is a list of eigenvectors forming a
291309
basis for the corresponding right eigenspace, and n is the

0 commit comments

Comments
 (0)