code: def is_tensor_and_is_compatible(
      tensor_type1, tensor_type2, allow_promotion=False
  ):
      """
      Try to find a tensor type compatible with both input types.
  
      Compatible means that the tensors have the same rank and matching or unspecified
      dimensions. For example, (10, -1) is compatible with (-1, 20) with the compatible
      shape (10, 20).
  
      Args:
          tensor_type1 (types.tensor)
          tensor_type2 (types.tensor)
          allow_promotion (bool): If True, allow primitive types to be promoted.
  
      Returns:
          A pair of (bool, type). If the given types are not tensor types with
          (1) compatible shapes and (2) either identical primitive types or
          allow_promition=True, return is False, None. Otherwise, return True
          and the compatible shape. Note that the returned shape may
          not be the same as either input. For example,
  
          is_tensor_and_is_compatible(
              tensor[fp32,[10,-1]],
              tensor[fp32,[-1,20]]) --> tensor[fp32, [10,20]]
      """
  
      if not is_tensor(tensor_type1) or not is_tensor(tensor_type2):
          return False, None
      shape1 = tensor_type1.get_shape()
      shape2 = tensor_type2.get_shape()
  
      primitive_type = tensor_type1.get_primitive()
      if primitive_type != tensor_type2.get_primitive():
          promoted_type = promote_types(
              primitive_type, tensor_type2.get_primitive()
          )
          if allow_promotion:
              primitive_type = promoted_type
          else:
              return False, promoted_type
  
      if len(shape1) == 0:
          return True, tensor_type2
      if len(shape2) == 0:
          return True, tensor_type1
  
      if len(shape1) != len(shape2):
          return False, None
  
      most_specific_shape = []
      for i in range(len(shape1)):
          if shape1[i] == -1 or issubclass(type(shape1[i]), sm.Basic):
              most_specific_shape.append(shape2[i])
          elif shape2[i] == -1 or issubclass(type(shape2[i]), sm.Basic):
              most_specific_shape.append(shape1[i])
          elif shape1[i] == shape2[i]:
              most_specific_shape.append(shape1[i])
          elif shape1[i] != shape2[i]:
              return False, None
  
      return True, tensor(primitive_type, most_specific_shape)
  
file_path: coremltools/coremltools/converters/mil/mil/types/type_tensor.py
imports: import numpy
  import sympy
  from coremltools import _logger
  from .get_type_info import get_type_info
  from .type_mapping import builtin_to_string, is_subtype, is_tensor, nptype_from_builtin, numpy_type_to_builtin_type, promote_types
  from .type_spec import Type
label_desc: Use image node_id 5 for calling a global function with example usage: is_tensor_and_is_compatible(tensor_type1, tensor_type2, allow_promotion) and returns: True,  tensor, False,  None, True,  tensor_type2, True,  tensor_type1, False,  None, False,  promoted_type, False,  None