(self)
| 137 | |
| 138 | @test_util.run_v1_only("b/120545219") |
| 139 | def Test(self): |
| 140 | is_complex = dtype_ in (np.complex64, np.complex128) |
| 141 | is_single = dtype_ in (np.float32, np.complex64) |
| 142 | tol = 3e-4 if is_single else 1e-12 |
| 143 | if test.is_gpu_available(): |
| 144 | # The gpu version returns results that are much less accurate. |
| 145 | tol *= 100 |
| 146 | np.random.seed(42) |
| 147 | x_np = np.random.uniform( |
| 148 | low=-1.0, high=1.0, size=np.prod(shape_)).reshape(shape_).astype(dtype_) |
| 149 | if is_complex: |
| 150 | x_np += 1j * np.random.uniform( |
| 151 | low=-1.0, high=1.0, |
| 152 | size=np.prod(shape_)).reshape(shape_).astype(dtype_) |
| 153 | |
| 154 | with self.session(use_gpu=True) as sess: |
| 155 | if use_static_shape_: |
| 156 | x_tf = constant_op.constant(x_np) |
| 157 | else: |
| 158 | x_tf = array_ops.placeholder(dtype_) |
| 159 | |
| 160 | if compute_uv_: |
| 161 | s_tf, u_tf, v_tf = linalg_ops.svd( |
| 162 | x_tf, compute_uv=compute_uv_, full_matrices=full_matrices_) |
| 163 | if use_static_shape_: |
| 164 | s_tf_val, u_tf_val, v_tf_val = self.evaluate([s_tf, u_tf, v_tf]) |
| 165 | else: |
| 166 | s_tf_val, u_tf_val, v_tf_val = sess.run( |
| 167 | [s_tf, u_tf, v_tf], feed_dict={x_tf: x_np}) |
| 168 | else: |
| 169 | s_tf = linalg_ops.svd( |
| 170 | x_tf, compute_uv=compute_uv_, full_matrices=full_matrices_) |
| 171 | if use_static_shape_: |
| 172 | s_tf_val = self.evaluate(s_tf) |
| 173 | else: |
| 174 | s_tf_val = sess.run(s_tf, feed_dict={x_tf: x_np}) |
| 175 | |
| 176 | if compute_uv_: |
| 177 | u_np, s_np, v_np = np.linalg.svd( |
| 178 | x_np, compute_uv=compute_uv_, full_matrices=full_matrices_) |
| 179 | else: |
| 180 | s_np = np.linalg.svd( |
| 181 | x_np, compute_uv=compute_uv_, full_matrices=full_matrices_) |
| 182 | # We explicitly avoid the situation where numpy eliminates a first |
| 183 | # dimension that is equal to one. |
| 184 | s_np = np.reshape(s_np, s_tf_val.shape) |
| 185 | |
| 186 | CompareSingularValues(self, s_np, s_tf_val, tol) |
| 187 | if compute_uv_: |
| 188 | CompareSingularVectors(self, u_np, u_tf_val, min(shape_[-2:]), tol) |
| 189 | CompareSingularVectors(self, |
| 190 | np.conj(np.swapaxes(v_np, -2, -1)), v_tf_val, |
| 191 | min(shape_[-2:]), tol) |
| 192 | CheckApproximation(self, x_np, u_tf_val, s_tf_val, v_tf_val, |
| 193 | full_matrices_, tol) |
| 194 | CheckUnitary(self, u_tf_val, tol) |
| 195 | CheckUnitary(self, v_tf_val, tol) |
| 196 |
nothing calls this directly
no test coverage detected