code: def test_icm_encode(self):
      d = 16
      n = 500
      M = 4
      nbits = 4
      K = 1 << nbits
  
      rs = np.random.RandomState(123)
      x = rs.rand(n, d).astype(np.float32)
  
      lsq = faiss.LocalSearchQuantizer(d, M, nbits)
      lsq.train(x)  # just for allocating memory for codebooks
  
      # compute binary terms
      binaries = np.zeros((M, M, K, K)).astype(np.float32)
      lsq.compute_binary_terms(sp(binaries))
  
      # compute unary terms
      unaries = np.zeros((M, n, K)).astype(np.float32)
      lsq.compute_unary_terms(sp(x), sp(unaries), n)
  
      # randomly generate codes
      codes = rs.randint(0, K, (n, M)).astype(np.int32)
      new_codes = codes.copy()
  
      # do icm encoding given binary and unary terms
      lsq.icm_encode_step(
          sp(new_codes), sp(unaries), sp(binaries), n, 1
      )
  
      # do icm encoding without pre-computed unary and bianry terms in Python
      codebooks = faiss.vector_float_to_array(lsq.codebooks)
      codebooks = codebooks.reshape(M, K, d).copy()
      ref_codes = icm_encode_ref(x, codebooks, codes)
  
      np.testing.assert_array_equal(new_codes, ref_codes)
  
imports: import numpy
  import faiss
  import unittest
  from faiss.contrib import datasets
label_desc: Use image node_id 7 for calling the TestComponents obj's underlying member method code with example usage: obj.test_icm_encode() without return types