code: def compare_binary_result_lists(D1, I1, D2, I2):
      """comparing result lists is difficult because there are many
      ties. Here we sort by (distance, index) pairs and ignore the largest
      distance of each result. Compatible result lists should pass this.
      """
      assert D1.shape == I1.shape == D2.shape == I2.shape
      n, k = D1.shape
      ndiff = (D1 != D2).sum()
      assert ndiff == 0, "%d differences in distance matrix %s" % (
          ndiff,
          D1.shape,
      )
  
      def normalize_DI(D, I):
          norm = I.max() + 1.0
          Dr = D.astype("float64") + I / norm
          # ignore -1s and elements on last column
          Dr[I1 == -1] = 1e20
          Dr[D == D[:, -1:]] = 1e20
          Dr.sort(axis=1)
          return Dr
  
      ndiff = (normalize_DI(D1, I1) != normalize_DI(D2, I2)).sum()
      assert ndiff == 0, "%d differences in normalized D matrix" % ndiff
  
file_path: faiss/tests/common_faiss_tests.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import numpy
  import faiss
label_desc: Use image node_id 5 for calling a global function with example usage: compare_binary_result_lists(D1, I1, D2, I2) and returns: Dr