code: def broadcast_shapes(shape_x, shape_y):
      """
      Check and broadcast given input shapes.
      :param shape_x: tuple of int or symbols
          Shape of the first tensor (possibly symbolic).
      :param shape_y: tuple of int or symbols
          Shape of the second tensor (possibly symbolic).
      :return: tuple of int or symbols
          Result from broadcast.
      """
      shape_x = tuple(shape_x)
      shape_y = tuple(shape_y)
      if len(shape_x) < len(shape_y):
          shape_x = tuple([1] * (len(shape_y) - len(shape_x))) + shape_x
      if len(shape_y) < len(shape_x):
          shape_y = tuple([1] * (len(shape_x) - len(shape_y))) + shape_y
  
      ret_shapes = list()
      for i in range(len(shape_x)):
          x_unknown = is_symbolic(shape_x[i])
          y_unknown = is_symbolic(shape_y[i])
          if shape_x[i] == 1:
              ret_shapes.append(shape_y[i])
          elif shape_y[i] == 1:
              ret_shapes.append(shape_x[i])
          elif not y_unknown and shape_y[i] > 1:
              if not x_unknown and shape_x[i] != shape_y[i]:
                  raise ValueError(
                      "Incompatible dim {} in shapes {} vs. {}".format(
                          i, shape_x, shape_y
                      )
                  )
              ret_shapes.append(shape_y[i])
          elif not x_unknown and shape_x[i] > 1:
              if not y_unknown and shape_x[i] != shape_y[i]:
                  raise ValueError(
                      "Incompatible dim {} in shapes {} vs. {}".format(
                          i, shape_x, shape_y
                      )
                  )
              ret_shapes.append(shape_x[i])
          elif x_unknown or y_unknown:
              ret_shapes.append(
                  sm.functions.Max(shape_x[i], shape_y[i])
              )
          else:
              assert shape_x[i] == shape_y[i]
              ret_shapes.append(shape_x[i])
  
      return tuple(ret_shapes)
  
file_path: turicreate/src/external/coremltools_wrap/coremltools/coremltools/converters/mil/mil/ops/defs/_utils.py
imports: import math
  import coremltools.converters
  import sympy
  from coremltools.converters.mil.mil.types.symbolic import is_symbolic
  from ._op_reqs import *
label_desc: Use image node_id 1 for calling a global function with example usage: broadcast_shapes(shape_x, shape_y) and returns: tuple