code: def test_binary_op():
      def inst(vars, sh):
          return [vars.get(s, s) for s in sh]
  
      def check_binary_op(opfunc, ref, dtype):
          # TODO(@jroesch): this piece of code improperly uses type variables.
          n = te.var("n")
          s1 = (5, n, 5)
          s2 = (n, 1)
          t1 = relay.TensorType(s1)
          t2 = relay.TensorType(s2)
          x = relay.var("x", t1, dtype=dtype)
          y = relay.var("y", t2, dtype=dtype)
          z = opfunc(x, y)
          # test printer
          assert ("{}(%x, %y)".format(z.op.name)) in z.astext()
          zz = run_infer_type(z)
          assert zz.checked_type == t1
  
          if ref is not None:
              t1 = relay.TensorType((5, 10, 5))
              t2 = relay.TensorType((5, 10, 5))
              x = relay.var("x", t1, dtype=dtype)
              y = relay.var("y", t2, dtype=dtype)
              z = opfunc(x, y)
              x_data = np.random.rand(5, 10, 5).astype(dtype)
              y_data = np.random.rand(5, 10, 5).astype(dtype)
              ref_res = ref(x_data, y_data)
              func = relay.Function([x, y], z)
  
              for target, dev in tvm.testing.enabled_targets():
                  # use graph by execuor default for testing, as we need
                  # create function explicitly to avoid constant-folding.
                  if (
                      dtype == "float16"
                      and target == "cuda"
                      and not have_fp16(tvm.cuda(0).compute_version)
                  ):
                      continue
                  op_res = relay.create_executor(
                      "graph", device=dev, target=target
                  ).evaluate(func)(x_data, y_data)
                  np.testing.assert_allclose(
                      op_res.numpy(), ref_res, rtol=0.01, atol=1e-3
                  )
  
      for opfunc, ref in [
          (relay.add, np.add),
          (relay.subtract, np.subtract),
          (relay.multiply, np.multiply),
          (relay.divide, np.divide),
          (relay.floor_divide, np.floor_divide),
          (relay.floor_mod, np.fmod),
      ]:
          for dtype in ["float16", "float32"]:
              check_binary_op(opfunc, ref, dtype)
  
imports: import numpy
  import pytest
  import tvm
  from tvm import te
  import scipy
  from tvm import relay
  import pytest
  from tvm.relay.testing import run_infer_type
  import tvm.topi.testing
  from tvm.contrib.nvcc import have_fp16
  import tvm.testing
  from tvm.topi.utils import get_const_tuple
label_desc: Use image node_id 4 for calling a global function with example usage: test_binary_op() and returns: unknown