Tests that compilation handles switch operators.
(self)
| 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() |
nothing calls this directly
no test coverage detected