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

Method testLoops

tensorflow/compiler/tests/jit_test.py:338–354  ·  view source on GitHub ↗

Tests that compilation accepts computations containing loops.

(self)

Source from the content-addressed store, hash-verified

336 self.assertAllClose(28, out)
337
338 def testLoops(self):
339 """Tests that compilation accepts computations containing loops."""
340
341 with self.session(config=NoRewriteSessionConfig()) as session:
342 x = array_ops.placeholder(dtypes.float32)
343 with jit_scope():
344 c = lambda i, _: math_ops.less(i, 5)
345 b = lambda i, x: (i + 1, x * 2.0 + 1.0)
346 _, y = control_flow_ops.while_loop(c, b, (constant_op.constant(0), x))
347
348 run_metadata = config_pb2.RunMetadata()
349 result = session.run(y, {x: np.float32(2)},
350 run_metadata=run_metadata,
351 options=config_pb2.RunOptions(
352 trace_level=config_pb2.RunOptions.FULL_TRACE))
353 self.assert_(MetadataHasXlaRunOp(run_metadata))
354 self.assertAllClose(result, np.float32(95), rtol=1e-1)
355
356 def testCond(self):
357 """Tests that compilation handles switch operators."""

Callers

nothing calls this directly

Calls 9

NoRewriteSessionConfigFunction · 0.85
MetadataHasXlaRunOpFunction · 0.85
RunMetadataMethod · 0.80
sessionMethod · 0.45
placeholderMethod · 0.45
while_loopMethod · 0.45
constantMethod · 0.45
runMethod · 0.45
assertAllCloseMethod · 0.45

Tested by

no test coverage detected