(self)
| 161 | |
| 162 | @test_util.run_deprecated_v1 |
| 163 | def testUnderflow(self): |
| 164 | x = [-1000, -1001, -1002, -1003] |
| 165 | for dtype in [np.float16, np.float32, np.double]: |
| 166 | x_np = np.array(x, dtype=dtype) |
| 167 | max_np = np.max(x_np) |
| 168 | with self.assertRaisesRegexp(RuntimeWarning, |
| 169 | "divide by zero encountered in log"): |
| 170 | out = log(np.sum(exp(x_np))) |
| 171 | if out == -np.inf: |
| 172 | raise RuntimeWarning("divide by zero encountered in log") |
| 173 | |
| 174 | with self.cached_session(use_gpu=True): |
| 175 | x_tf = constant_op.constant(x_np, shape=x_np.shape) |
| 176 | y_tf_np = math_ops.reduce_logsumexp(x_tf).eval() |
| 177 | y_np = log(np.sum(exp(x_np - max_np))) + max_np |
| 178 | self.assertAllClose(y_tf_np, y_np) |
| 179 | |
| 180 | @test_util.run_deprecated_v1 |
| 181 | def testInfinity(self): |
nothing calls this directly
no test coverage detected