Skip to content

Commit bfdf734

Browse files
committed
Make sure singular_values return Sequence and fix a bug
1 parent 1516bcc commit bfdf734

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/sage/matrix/matrix2.pyx

+16-6
Original file line numberDiff line numberDiff line change
@@ -6992,7 +6992,7 @@ cdef class Matrix(Matrix1):
69926992
extend=extend, algorithm=algorithm,
69936993
suppress_future_warning=False))
69946994

6995-
def singular_values(self):
6995+
def singular_values(self) -> Sequence:
69966996
"""
69976997
Return a sequence of singular values of a matrix.
69986998

@@ -7001,17 +7001,27 @@ cdef class Matrix(Matrix1):
70017001
sage: A = matrix([[1, 2], [3, 4]])
70027002
sage: A.singular_values()
70037003
[0.3659661906262578?, 5.464985704219043?]
7004-
sage: A = matrix(CC, [[1+I, 2], [3, 4]])
7004+
7005+
TESTS::
7006+
7007+
sage: type(A.singular_values())
7008+
<class 'sage.structure.sequence.Sequence_generic'>
7009+
sage: set_random_seed(100)
7010+
sage: A = matrix.random(CC, 5)
7011+
sage: Sequence((A*A.H).eigenvalues(), universe=RR)
7012+
Traceback (most recent call last):
7013+
...
7014+
TypeError: unable to convert ... to an element of Real Field with 53 bits of precision
70057015
sage: A.singular_values() # abs tol 1e-13
7006-
[0.811897727761428, 5.50825036464900]
7016+
[0.317896596475411, 1.25232496300299, 1.48403213017074, 2.08062167993720, 2.59091978815526]
70077017
"""
70087018
from sage.rings.abc import ComplexField
7009-
e = (self*self.H).eigenvalues() # guaranteed to be real
7019+
e: Sequence = (self*self.H).eigenvalues() # guaranteed to be real
70107020
R = self.base_ring()
70117021
if isinstance(R, ComplexField):
70127022
# because of floating point error e may not be all real
7013-
e = list(map(R._real_field(), e))
7014-
return [x.sqrt() for x in e]
7023+
e = Sequence([x.real() for x in e], universe=R._real_field())
7024+
return Sequence([x.sqrt() for x in e])
70157025

70167026
def _eigenvectors_result_to_eigenvalues(self, eigenvectors: list) -> Sequence:
70177027
"""

0 commit comments

Comments
 (0)