Tests that compilation accepts computations containing loops.
(self)
| 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.""" |
nothing calls this directly
no test coverage detected