docstr: Test explicit marking of operators to compile.
docstr_tok: ["Test","explicit","marking","of","operators","to","compile","."]
code: def testExplicitMarking(self):
      """Test explicit marking of operators to compile."""
      batch_size = 16
      image_size = 28 * 28
      num_classes = 10
  
      with ops.Graph().as_default():
          x = array_ops.placeholder(dtypes.float32)
          w = array_ops.placeholder(dtypes.float32)
          b = array_ops.placeholder(dtypes.float32)
          with jit_scope():
              y1 = math_ops.matmul(x, w)
          y2 = math_ops.add(y1, b)
          with jit_scope():
              y = math_ops.square(y2)
  
          dw = np.random.random_sample(
              (image_size, num_classes)
          ).astype(np.float32)
          db = np.random.random_sample((num_classes)).astype(np.float32)
          dx = np.random.random_sample((batch_size, image_size)).astype(
              np.float32
          )
          with session_lib.Session() as sess:
              run_metadata = config_pb2.RunMetadata()
              output = test_utils.RunWithWarmup(
                  sess,
                  y,
                  {x: dx, w: dw, b: db},
                  run_metadata=run_metadata,
                  options=config_pb2.RunOptions(
                      trace_level=config_pb2.RunOptions.FULL_TRACE
                  ),
              )
  
              # TODO(phawkins): really we would like to test that there were exactly
              # two kernel launches. However, we have no reliable way to determine
              # that.
              self.assertTrue(MetadataHasXlaRunOp(run_metadata))
  
              expected = np.square(np.dot(dx, dw) + db)
              self.assertAllClose(expected, output, 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 10 for calling the JitLaunchTest obj's underlying member method code with example usage: obj.testExplicitMarking() without return types