Skip to content

Commit f949fe1

Browse files
committed
Handled sparse case in a cleaner way for euclidean norm
1 parent 3815074 commit f949fe1

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/sage/matrix/matrix2.pyx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16499,13 +16499,11 @@ cdef class Matrix(Matrix1):
1649916499
if p == 2:
1650016500
from sage.rings.complex_double import CDF
1650116501

16502-
# Sparse matrices don't expose the ``SVD`` method.
16503-
if self.is_sparse():
16504-
A = self.dense_matrix().change_ring(CDF)
16505-
else:
16506-
A = self.change_ring(CDF)
16507-
16508-
A = A.conjugate().transpose() * A
16502+
# Always try to convert to ``dense_matrix`` since sparse matrices
16503+
# don't expose the ``SVD`` method. If the matrix is already dense,
16504+
# the cost is negligible.
16505+
A = self.dense_matrix().change_ring(CDF)
16506+
A = A.conjugate_transpose() * A
1650916507
S = A.SVD()[1]
1651016508
return max(S.list()).real().sqrt()
1651116509

0 commit comments

Comments
 (0)