(self)
| 140 | CompareEigenVectors(self, x_vi, y_vi, tol) |
| 141 | |
| 142 | def Test(self): |
| 143 | np.random.seed(1) |
| 144 | n = shape_[-1] |
| 145 | batch_shape = shape_[:-2] |
| 146 | np_dtype = dtype_.as_numpy_dtype |
| 147 | a = np.random.uniform( |
| 148 | low=-1.0, high=1.0, size=n * n).reshape([n, n]).astype(np_dtype) |
| 149 | if dtype_.is_complex: |
| 150 | a += 1j * np.random.uniform( |
| 151 | low=-1.0, high=1.0, size=n * n).reshape([n, n]).astype(np_dtype) |
| 152 | a += np.conj(a.T) |
| 153 | a = np.tile(a, batch_shape + (1, 1)) |
| 154 | if dtype_ in (dtypes_lib.float32, dtypes_lib.complex64): |
| 155 | atol = 1e-4 |
| 156 | else: |
| 157 | atol = 1e-12 |
| 158 | np_e, np_v = np.linalg.eigh(a) |
| 159 | with self.session(use_gpu=True): |
| 160 | if compute_v_: |
| 161 | tf_e, tf_v = linalg_ops.self_adjoint_eig(constant_op.constant(a)) |
| 162 | |
| 163 | with ops.device("/cpu:0"): |
| 164 | # Check that V*diag(E)*V^T is close to A. |
| 165 | a_ev = math_ops.matmul( |
| 166 | math_ops.matmul(tf_v, array_ops.matrix_diag(tf_e)), |
| 167 | tf_v, |
| 168 | adjoint_b=True) |
| 169 | self.assertAllClose(self.evaluate(a_ev), a, atol=atol) |
| 170 | |
| 171 | # Compare to numpy.linalg.eigh. |
| 172 | CompareEigenDecompositions(self, np_e, np_v, self.evaluate(tf_e), |
| 173 | self.evaluate(tf_v), atol) |
| 174 | else: |
| 175 | tf_e = linalg_ops.self_adjoint_eigvals(constant_op.constant(a)) |
| 176 | self.assertAllClose( |
| 177 | np.sort(np_e, -1), np.sort(self.evaluate(tf_e), -1), atol=atol) |
| 178 | |
| 179 | return Test |
| 180 |
nothing calls this directly
no test coverage detected