parameters: (top_from, top_to)
docstring: Determine the coordinate mapping betweeen a top (from) and a top (to).
      Walk the graph to find a common ancestor while composing the coord maps for
      from and to until they meet. As a last step the from map is inverted.
docstring_summary: Determine the coordinate mapping betweeen a top (from) and a top (to).
      Walk the graph to find a common ancestor while composing the coord maps for
      from and to until they meet. As a last step the from map is inverted.
docstring_tokens: Determine the coordinate mapping betweeen a top ( from ) and a top ( to ) . Walk the graph to find a common ancestor while composing the coord maps for from and to until they meet . As a last step the from map is inverted .
function: def coord_map_from_to(top_from, top_to):
      """
      Determine the coordinate mapping betweeen a top (from) and a top (to).
      Walk the graph to find a common ancestor while composing the coord maps for
      from and to until they meet. As a last step the from map is inverted.
      """
      # We need to find a common ancestor of top_from and top_to.
      # We'll assume that all ancestors are equivalent here (otherwise the graph
      # is an inconsistent state (which we could improve this to check for)).
      # For now use a brute-force algorithm.
  
      def collect_bottoms(top):
          """
          Collect the bottoms to walk for the coordinate mapping.
          The general rule is that all the bottoms of a layer can be mapped, as
          most layers have the same coordinate mapping for each bottom.
          Crop layer is a notable exception. Only the first/cropped bottom is
          mappable; the second/dimensions bottom is excluded from the walk.
          """
          bottoms = top.fn.inputs
          if top.fn.type_name == 'Crop':
              bottoms = bottoms[:1]
          return bottoms
  
      # walk back from top_from, keeping the coord map as we go
      from_maps = {top_from: (None, 1, 0)}
      frontier = {top_from}
      while frontier:
          top = frontier.pop()
          try:
              bottoms = collect_bottoms(top)
              for bottom in bottoms:
                  from_maps[bottom] = compose(from_maps[top], coord_map(top.fn))
                  frontier.add(bottom)
          except UndefinedMapException:
              pass
  
      # now walk back from top_to until we hit a common blob
      to_maps = {top_to: (None, 1, 0)}
      frontier = {top_to}
      while frontier:
          top = frontier.pop()
          if top in from_maps:
              return compose(to_maps[top], inverse(from_maps[top]))
          try:
              bottoms = collect_bottoms(top)
              for bottom in bottoms:
                  to_maps[bottom] = compose(to_maps[top], coord_map(top.fn))
                  frontier.add(bottom)
          except UndefinedMapException:
              continue
  
      # if we got here, we did not find a blob in common
      raise RuntimeError('Could not compute map between tops; are they '
                         'connected by spatial layers?')
function_tokens: def coord_map_from_to ( top_from , top_to ) : # We need to find a common ancestor of top_from and top_to. # We'll assume that all ancestors are equivalent here (otherwise the graph # is an inconsistent state (which we could improve this to check for)). # For now use a brute-force algorithm. def collect_bottoms ( top ) : """
          Collect the bottoms to walk for the coordinate mapping.
          The general rule is that all the bottoms of a layer can be mapped, as
          most layers have the same coordinate mapping for each bottom.
          Crop layer is a notable exception. Only the first/cropped bottom is
          mappable; the second/dimensions bottom is excluded from the walk.
          """ bottoms = top . fn . inputs if top . fn . type_name == 'Crop' : bottoms = bottoms [ : 1 ] return bottoms # walk back from top_from, keeping the coord map as we go from_maps = { top_from : ( None , 1 , 0 ) } frontier = { top_from } while frontier : top = frontier . pop ( ) try : bottoms = collect_bottoms ( top ) for bottom in bottoms : from_maps [ bottom ] = compose ( from_maps [ top ] , coord_map ( top . fn ) ) frontier . add ( bottom ) except UndefinedMapException : pass # now walk back from top_to until we hit a common blob to_maps = { top_to : ( None , 1 , 0 ) } frontier = { top_to } while frontier : top = frontier . pop ( ) if top in from_maps : return compose ( to_maps [ top ] , inverse ( from_maps [ top ] ) ) try : bottoms = collect_bottoms ( top ) for bottom in bottoms : to_maps [ bottom ] = compose ( to_maps [ top ] , coord_map ( top . fn ) ) frontier . add ( bottom ) except UndefinedMapException : continue # if we got here, we did not find a blob in common raise RuntimeError ( 'Could not compute map between tops; are they ' 'connected by spatial layers?' )