code: def do_test_codec(self, nbit):
      pq = faiss.ProductQuantizer(16, 2, nbit)
  
      # simulate training
      rs = np.random.RandomState(123)
      centroids = rs.rand(2, 1 << nbit, 8).astype("float32")
      faiss.copy_array_to_vector(centroids.ravel(), pq.centroids)
  
      idx = rs.randint(1 << nbit, size=(100, 2))
      # can be encoded exactly
      x = np.hstack((centroids[0, idx[:, 0]], centroids[1, idx[:, 1]]))
  
      # encode / decode
      codes = pq.compute_codes(x)
      xr = pq.decode(codes)
      assert np.all(xr == x)
  
      # encode w/ external index
      assign_index = faiss.IndexFlatL2(8)
      pq.assign_index = assign_index
      codes2 = np.empty((100, pq.code_size), dtype="uint8")
      pq.compute_codes_with_assign_index(
          faiss.swig_ptr(x), faiss.swig_ptr(codes2), 100
      )
      assert np.all(codes == codes2)
  
imports: from __future__ import absolute_import, division, print_function
  import numpy
  import faiss
  import unittest
label_desc: Use image node_id 2 for calling the TestProductQuantizer obj's underlying member method code with example usage: obj.do_test_codec(nbit) without return types