code: def icm_encode_ref(x, codebooks, codes):
      n, d = x.shape
      M, K, d = codebooks.shape
  
      codes = codes.copy()
      for m in range(M):
          objs = np.zeros((n, K), dtype=np.float32)  # [n, K]
          for code in range(K):
              new_codes = codes.copy()
              new_codes[:, m] = code
  
              # decode x
              decoded_x = decode_ref(x, codebooks, new_codes)
              objs[:, code] = np.sum((x - decoded_x) ** 2, axis=1)
  
          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 7 for calling a global function with example usage: icm_encode_ref(x, codebooks, codes) and returns: codes