code: def icm_encode_step_ref(unaries, binaries, codes):
      M, n, K = unaries.shape
  
      for m in range(M):
          objs = unaries[m].copy()  # [n, K]
  
          for m2 in range(M):  # pair, m2 != m
              if m2 == m:
                  continue
  
              for i in range(n):
                  for code in range(K):
                      code2 = codes[i, m2]
                      objs[i, code] += binaries[m, m2, code, code2]
  
          codes[:, m] = np.argmin(objs, axis=1)
  
      return codes
  
imports: import numpy
  import faiss
  import unittest
  from faiss.contrib import datasets
label_desc: Use image node_id 5 for calling a global function with example usage: icm_encode_step_ref(unaries, binaries, codes) and returns: codes