parameters: (shape_x, shape_y)
return_statement: return tuple(ret_shapes)
docstring: 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.
docstring_summary: 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.
docstring_tokens: 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 .
function: 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)
function_tokens: def broadcast_shapes ( shape_x , shape_y ) : 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 )