code: def _merge_tensor_type(old_type, obtained_type, backend):
      """Merges an updated instructions.TensorType for a single field."""
      if old_type is None:
          return obtained_type
      # Update the inferred dtype.
      if obtained_type is None:
          return old_type
      # One of old_type or obtained_type must be a TensorType because that's when
      # the caller's pattern_map2 would call _merge_tensor_type.
      if not isinstance(old_type, instructions.TensorType):
          raise ValueError(
              "Type mismatch: Expected struct type {}, got {}".format(
                  old_type, obtained_type
              )
          )
      if not isinstance(obtained_type, instructions.TensorType):
          raise ValueError(
              "Type mismatch: Expected tensor type {}, got {}".format(
                  old_type, obtained_type
              )
          )
      dtype = old_type.dtype
      obtained_dtype = obtained_type.dtype
      if dtype is None:
          dtype = obtained_dtype
      elif obtained_dtype is not None:
          dtype = backend.merge_dtypes(dtype, obtained_dtype)
      # Update the inferred shape.
      shape = old_type.shape
      obtained_shape = obtained_type.shape
      if shape is None:
          shape = obtained_shape
      elif obtained_shape is not None:
          shape = backend.merge_shapes(shape, obtained_shape)
      return instructions.TensorType(dtype, shape)
  
file_path: probability/tensorflow_probability/python/experimental/auto_batching/type_inference.py
imports: import contextlib
  import functools
  from absl import logging
  import six
  from tensorflow_probability.python.experimental.auto_batching import instructions
label_desc: Use image node_id 2 for calling a global function with example usage: _merge_tensor_type(old_type, obtained_type, backend) and returns: instructions, obtained_type, old_type