From: Michael Orlitzky Date: Sun, 4 Nov 2018 06:36:39 +0000 (-0500) Subject: cone/symmetric_psd.py: use a generator expression in unit_eigenvectors(). X-Git-Url: http://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=b4ba438a4410fed2c7e77d9f619680750cb42c8f;p=sage.d.git cone/symmetric_psd.py: use a generator expression in unit_eigenvectors(). --- diff --git a/mjo/cone/symmetric_psd.py b/mjo/cone/symmetric_psd.py index ef5d477..68be78f 100644 --- a/mjo/cone/symmetric_psd.py +++ b/mjo/cone/symmetric_psd.py @@ -69,12 +69,15 @@ def unit_eigenvectors(A): INPUT: - - ``A`` - The matrix whose eigenvectors we want to compute. + - ``A`` -- The matrix whose unit eigenvectors we want to compute. OUTPUT: A list of (eigenvalue, eigenvector) pairs where each eigenvector is - associated with its paired eigenvalue of ``A`` and has norm `1`. + associated with its paired eigenvalue of ``A`` and has norm `1`. If + the base ring of ``A`` is not algebraically closed, then returned + eigenvectors may (necessarily) be over its algebraic closure and not + the base ring of ``A`` itself. SETUP:: @@ -83,7 +86,7 @@ def unit_eigenvectors(A): EXAMPLES:: sage: A = matrix(QQ, [[0, 2, 3], [2, 0, 0], [3, 0, 0]]) - sage: unit_evs = unit_eigenvectors(A) + sage: unit_evs = list(unit_eigenvectors(A)) sage: bool(unit_evs[0][1].norm() == 1) True sage: bool(unit_evs[1][1].norm() == 1) @@ -92,17 +95,9 @@ def unit_eigenvectors(A): True """ - # This will give us a list of lists whose elements are the - # eigenvectors we want. - ev_lists = [ (val,vecs) for (val,vecs,multiplicity) - in A.eigenvectors_right() ] - - # Pair each eigenvector with its eigenvalue and normalize it. - evs = [ [(l, vec/vec.norm()) for vec in vecs] for (l,vecs) in ev_lists ] - - # Flatten the list, abusing the fact that "+" is overloaded on lists. - return sum(evs, []) - + return ( (val,vec.normalized()) + for (val,vecs,multiplicity) in A.eigenvectors_right() + for vec in vecs )