(self)
| 143 | |
| 144 | @test_util.run_deprecated_v1 |
| 145 | def testOverflow(self): |
| 146 | x = [1000, 1001, 1002, 1003] |
| 147 | for dtype in [np.float16, np.float32, np.double]: |
| 148 | x_np = np.array(x, dtype=dtype) |
| 149 | max_np = np.max(x_np) |
| 150 | with self.assertRaisesRegexp(RuntimeWarning, |
| 151 | "overflow encountered in exp"): |
| 152 | out = log(np.sum(exp(x_np))) |
| 153 | if out == np.inf: |
| 154 | raise RuntimeWarning("overflow encountered in exp") |
| 155 | |
| 156 | with self.cached_session(use_gpu=True): |
| 157 | x_tf = constant_op.constant(x_np, shape=x_np.shape) |
| 158 | y_tf_np = math_ops.reduce_logsumexp(x_tf).eval() |
| 159 | y_np = log(np.sum(exp(x_np - max_np))) + max_np |
| 160 | self.assertAllClose(y_tf_np, y_np) |
| 161 | |
| 162 | @test_util.run_deprecated_v1 |
| 163 | def testUnderflow(self): |
nothing calls this directly
no test coverage detected