code: def do_test(self, d, dsub, nbit=8, metric=None):
      if metric is None:
          self.do_test(d, dsub, nbit, faiss.METRIC_INNER_PRODUCT)
          self.do_test(d, dsub, nbit, faiss.METRIC_L2)
          return
      # faiss.cvar.distance_compute_blas_threshold = 1000000
  
      M = d // dsub
      pq = faiss.ProductQuantizer(d, M, nbit)
      xt = faiss.randn((max(1000, pq.ksub * 50), d), 123)
      pq.cp.niter = 4  # to avoid timeouts in tests
      pq.train(xt)
  
      centroids = faiss.vector_to_array(pq.centroids)
      centroids = centroids.reshape(pq.M, pq.ksub, pq.dsub)
  
      nx = 100
      x = faiss.randn((nx, d), 555)
  
      ref_tab = np.zeros((nx, M, pq.ksub), "float32")
  
      # computation of tables in numpy
      for sq in range(M):
          i0, i1 = sq * dsub, (sq + 1) * dsub
          xsub = x[:, i0:i1]
          centsq = centroids[sq, :, :]
          if metric == faiss.METRIC_INNER_PRODUCT:
              ref_tab[:, sq, :] = xsub @ centsq.T
          elif metric == faiss.METRIC_L2:
              xsub3 = xsub.reshape(nx, 1, dsub)
              cent3 = centsq.reshape(1, pq.ksub, dsub)
              ref_tab[:, sq, :] = ((xsub3 - cent3) ** 2).sum(2)
          else:
              assert False
  
      sp = faiss.swig_ptr
  
      new_tab = np.zeros((nx, M, pq.ksub), "float32")
      if metric == faiss.METRIC_INNER_PRODUCT:
          pq.compute_inner_prod_tables(nx, sp(x), sp(new_tab))
      elif metric == faiss.METRIC_L2:
          pq.compute_distance_tables(nx, sp(x), sp(new_tab))
      else:
          assert False
  
      # compute sdc tables in numpy
      cent1 = np.expand_dims(centroids, axis=2)  # [M, ksub, 1, dsub]
      cent2 = np.expand_dims(centroids, axis=1)  # [M, 1, ksub, dsub]
      ref_sdc_tab = ((cent1 - cent2) ** 2).sum(3)
  
      pq.compute_sdc_table()
      new_sdc_tab = faiss.vector_to_array(pq.sdc_table)
      new_sdc_tab = new_sdc_tab.reshape(M, pq.ksub, pq.ksub)
  
      np.testing.assert_array_almost_equal(ref_tab, new_tab, decimal=5)
      np.testing.assert_array_almost_equal(
          ref_sdc_tab, new_sdc_tab, decimal=5
      )
  
imports: from __future__ import absolute_import, division, print_function
  import numpy
  import faiss
  import unittest
label_desc: Use image node_id 1 for calling the TestPQTables obj's underlying member method code with example usage: obj.do_test(d, dsub, nbit, metric) without return types