code: def is_tensor_and_is_compatible_general_shape(
      tensor_type1, tensor_type2
  ):
      # returns a pair of (bool, type)
      # If Both are tensors, and have compatible shape, the first return is true
      # The return will be the most general version of the tensor type.
      # Note that this may not be either tensor types. i.e.
      #
      # is_tensor_and_is_compatible(tensor[fp32,[10,-1]] ,tensor[fp32,[-1,20]])
      # will return True, tensor[fp32, [-1,-1]]
  
      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()
  
      if tensor_type1.get_primitive() != tensor_type2.get_primitive():
          return False, None
  
      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_general_shape = []
      for i in range(len(shape1)):
          if shape1[i] == -1 or issubclass(type(shape1[i]), sm.Basic):
              most_general_shape.append(shape1[i])
          elif shape2[i] == -1 or issubclass(type(shape2[i]), sm.Basic):
              most_general_shape.append(shape2[i])
          elif shape1[i] == shape2[i]:
              most_general_shape.append(shape1[i])
          elif shape1[i] != shape2[i]:
              return False, None
  
      return True, tensor(
          tensor_type1.get_primitive(), most_general_shape
      )
  
file_path: turicreate/src/external/coremltools_wrap/coremltools/coremltools/converters/mil/mil/types/type_tensor.py
imports: from __future__ import print_function
  from __future__ import division
  from __future__ import absolute_import
  import numpy
  import sympy
  import logging
  from .type_spec import Type
  from .get_type_info import get_type_info
  from .type_mapping import promote_types, is_tensor, nptype_from_builtin, builtin_to_string, numpy_type_to_builtin_type
label_desc: Use image node_id 5 for calling a global function with example usage: is_tensor_and_is_compatible_general_shape(tensor_type1, tensor_type2) and returns: True,  tensor, False,  None, False,  None, True,  tensor_type2, True,  tensor_type1, False,  None, False,  None