| 214 | tol = 1e-7 |
| 215 | with self.session(use_gpu=True): |
| 216 | def Compute(x): |
| 217 | e, v = linalg_ops.self_adjoint_eig(x) |
| 218 | # (complex) Eigenvectors are only unique up to an arbitrary phase |
| 219 | # We normalize the vectors such that the first component has phase 0. |
| 220 | top_rows = v[..., 0:1, :] |
| 221 | if dtype_.is_complex: |
| 222 | angle = -math_ops.angle(top_rows) |
| 223 | phase = math_ops.complex(math_ops.cos(angle), math_ops.sin(angle)) |
| 224 | else: |
| 225 | phase = math_ops.sign(top_rows) |
| 226 | v *= phase |
| 227 | return e, v |
| 228 | |
| 229 | if compute_v_: |
| 230 | funcs = [lambda x: Compute(x)[0], lambda x: Compute(x)[1]] |