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

Method testUnderflow

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

Source from the content-addressed store, hash-verified

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

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