MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / testOverflow

Method testOverflow

tensorflow/python/ops/math_ops_test.py:145–160  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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):

Callers

nothing calls this directly

Calls 8

logFunction · 0.50
expFunction · 0.50
maxMethod · 0.45
sumMethod · 0.45
cached_sessionMethod · 0.45
constantMethod · 0.45
evalMethod · 0.45
assertAllCloseMethod · 0.45

Tested by

no test coverage detected