code: def hash_module(matrix, labeling):
      """Computes a graph-invariance MD5 hash of the matrix and label pair.
  
      Args:
        matrix: np.ndarray square upper-triangular adjacency matrix.
        labeling: list of int labels of length equal to both dimensions of
          matrix.
  
      Returns:
        MD5 hash of the matrix and labeling.
      """
      vertices = np.shape(matrix)[0]
      in_edges = np.sum(matrix, axis=0).tolist()
      out_edges = np.sum(matrix, axis=1).tolist()
  
      assert len(in_edges) == len(out_edges) == len(labeling)
      hashes = list(zip(out_edges, in_edges, labeling))
      hashes = [
          hashlib.md5(str(h).encode("utf-8")).hexdigest()
          for h in hashes
      ]
      # Computing this up to the diameter is probably sufficient but since the
      # operation is fast, it is okay to repeat more times.
      for _ in range(vertices):
          new_hashes = []
          for v in range(vertices):
              in_neighbors = [
                  hashes[w] for w in range(vertices) if matrix[w, v]
              ]
              out_neighbors = [
                  hashes[w] for w in range(vertices) if matrix[v, w]
              ]
              new_hashes.append(
                  hashlib.md5(
                      (
                          "".join(sorted(in_neighbors))
                          + "|"
                          + "".join(sorted(out_neighbors))
                          + "|"
                          + hashes[v]
                      ).encode("utf-8")
                  ).hexdigest()
              )
          hashes = new_hashes
      fingerprint = hashlib.md5(
          str(sorted(hashes)).encode("utf-8")
      ).hexdigest()
  
      return fingerprint
  
file_path: singa/examples/model_selection/TRAILS-Database-Native-Model-Selection/internal/ml/model_selection/src/third_pkg/sp101_lib/graph_util.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import hashlib
  import itertools
  import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: hash_module(matrix, labeling) and returns: fingerprint