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

Method testCond

tensorflow/compiler/tests/jit_test.py:356–383  ·  view source on GitHub ↗

Tests that compilation handles switch operators.

(self)

Source from the content-addressed store, hash-verified

354 self.assertAllClose(result, np.float32(95), rtol=1e-1)
355
356 def testCond(self):
357 """Tests that compilation handles switch operators."""
358
359 with self.session(config=NoRewriteSessionConfig()) as session:
360 x = array_ops.placeholder(dtypes.float32)
361 y = array_ops.placeholder(dtypes.float32)
362 c = array_ops.placeholder(dtypes.bool)
363 with jit_scope():
364 z = x + 1.0
365 w = control_flow_ops.cond(c, lambda: z, lambda: y)
366 t = math_ops.add(z, w)
367
368 # If JIT compilation chooses to cluster z and t, then execution will
369 # deadlock.
370
371 run_metadata = config_pb2.RunMetadata()
372 result = test_utils.RunWithWarmup(
373 session,
374 t, {
375 x: np.float32(2),
376 y: np.float32(4),
377 c: True
378 },
379 run_metadata=run_metadata,
380 options=config_pb2.RunOptions(
381 trace_level=config_pb2.RunOptions.FULL_TRACE))
382 self.assert_(MetadataHasXlaRunOp(run_metadata))
383 self.assertAllClose(result, np.float32(6), rtol=1e-1)
384
385 def testNestedFunction(self):
386 g = ops.Graph()

Callers

nothing calls this directly

Calls 8

NoRewriteSessionConfigFunction · 0.85
MetadataHasXlaRunOpFunction · 0.85
RunMetadataMethod · 0.80
sessionMethod · 0.45
placeholderMethod · 0.45
condMethod · 0.45
addMethod · 0.45
assertAllCloseMethod · 0.45

Tested by

no test coverage detected