code: def compute_nn_path_lengths(A, top_order, path_type):
      """Computes the path lengths on a NN with adjacency matrix A to top_order[-1].
      top_order is a topological ordering of the nodes.
      A(i,j) is finite means there is an edge between i and j.
      """
      if path_type in "shortest":
          get_curr_length_from_child_lengths = min
      elif path_type == "longest":
          get_curr_length_from_child_lengths = max
      elif path_type == "rw":
          get_curr_length_from_child_lengths = lambda x: sum(x) / float(
              len(x)
          )
      else:
          raise ValueError("Unknown path_type: %s." % (path_type))
      # Now the algorithm
      all_vertices = np.array(range(A.shape[0]))
      source = top_order[-1]
      all_dists = np.array([np.inf] * A.shape[0])
      all_dists[source] = 0
      for layer_idx in reversed(top_order[:-1]):
          curr_children = all_vertices[A[layer_idx] < np.inf]
          children_path_lengths = [
              all_dists[ch_idx] for ch_idx in curr_children
          ]
          children_path_lengths = [
              children_path_lengths[i] + A[layer_idx, curr_children[i]]
              for i in range(len(curr_children))
          ]
          all_dists[layer_idx] = get_curr_length_from_child_lengths(
              children_path_lengths
          )
      return all_dists
  
file_path: dragonfly/dragonfly/utils/graph_utils.py
imports: from copy import deepcopy
  import numpy
  from scipy.linalg import eigh
  from .general_utils import get_nonzero_indices_in_vector
label_desc: Use image node_id 14 for calling a global function with example usage: compute_nn_path_lengths(A, top_order, path_type) and returns: all_dists