class_docstr: Tests for auto-compilation on CPU/GPU devices.
docstr: Tests that compilation handles switch operators.
docstr_tok: ["Tests","that","compilation","handles","switch","operators","."]
code: def testCond(self):
      """Tests that compilation handles switch operators."""
  
      with self.session(config=NoRewriteSessionConfig()) as session:
          x = array_ops.placeholder(dtypes.float32)
          y = array_ops.placeholder(dtypes.float32)
          c = array_ops.placeholder(dtypes.bool)
          with jit_scope():
              z = x + 1.0
              w = cond.cond(c, lambda: z, lambda: y)
              t = math_ops.add(z, w)
  
          # If JIT compilation chooses to cluster z and t, then execution will
          # deadlock.
  
          run_metadata = config_pb2.RunMetadata()
          result = test_utils.RunWithWarmup(
              session,
              t,
              {x: np.float32(2), y: np.float32(4), c: True},
              run_metadata=run_metadata,
              options=config_pb2.RunOptions(
                  trace_level=config_pb2.RunOptions.FULL_TRACE
              ),
          )
          self.assertTrue(MetadataHasXlaRunOp(run_metadata))
          self.assertAllClose(result, np.float32(6), rtol=1e-1)
  
imports: import os
  import numpy
  from tensorflow.compiler.tests import test_utils
  from tensorflow.core.protobuf import config_pb2
  from tensorflow.core.protobuf import rewriter_config_pb2
  from tensorflow.python.client import session
  from tensorflow.python.compiler.xla import jit
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import function
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import cond
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import gradients_impl
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import nn_ops
  from tensorflow.python.ops import while_loop
  from tensorflow.python.platform import test
label_desc: Use image node_id 4 for calling the XlaCompilationTest obj's underlying member method code with example usage: obj.testCond() without return types