class_docstr: tests IP in addition to L2, non multiple of 8 dimensions
class_docstr_tok: ["tests","IP","in","addition","to","L2",",","non","multiple","of","8","dimensions"]
code: def subtest(self, mt):
      d = 32
      xt, xb, xq = get_dataset_2(d, 2000, 1000, 200)
      nlist = 64
  
      gt_index = faiss.IndexFlat(d, mt)
      gt_index.add(xb)
      gt_D, gt_I = gt_index.search(xq, 10)
      quantizer = faiss.IndexFlat(d, mt)
      for (
          qname
      ) in "8bit 4bit 8bit_uniform 4bit_uniform fp16 6bit".split():
          qtype = getattr(faiss.ScalarQuantizer, "QT_" + qname)
          index = faiss.IndexIVFScalarQuantizer(
              quantizer, d, nlist, qtype, mt
          )
          index.train(xt)
          index.add(xb)
          index.nprobe = 4  # hopefully more robust than 1
          D, I = index.search(xq, 10)
          ninter = faiss.eval_intersection(I, gt_I)
          print("(%d, %s): %d, " % (mt, repr(qname), ninter))
          assert abs(ninter - self.ref_results[(mt, qname)]) <= 10
  
          if qname == "6bit":
              # the test below fails triggers ASAN. TODO check what's wrong
              continue
  
          D2, I2 = self.subtest_add2col(xb, xq, index, qname)
          assert np.all(I2 == I)
  
          # also test range search
  
          if mt == faiss.METRIC_INNER_PRODUCT:
              radius = float(D[:, -1].max())
          else:
              radius = float(D[:, -1].min())
          # print("radius", radius)
  
          lims, D3, I3 = index.range_search(xq, radius)
          ntot = ndiff = 0
          for i in range(len(xq)):
              l0, l1 = lims[i], lims[i + 1]
              Inew = set(I3[l0:l1])
              if mt == faiss.METRIC_INNER_PRODUCT:
                  mask = D2[i] > radius
              else:
                  mask = D2[i] < radius
              Iref = set(I2[i, mask])
              ndiff += len(Inew ^ Iref)
              ntot += len(Iref)
          # print("ndiff %d / %d" % (ndiff, ntot))
          assert ndiff < ntot * 0.01
  
          for pm in 1, 2:
              # print("parallel_mode=%d" % pm)
              index.parallel_mode = pm
              lims4, D4, I4 = index.range_search(xq, radius)
              # print("sizes", lims4[1:] - lims4[:-1])
              for qno in range(len(lims) - 1):
                  Iref = I3[lims[qno] : lims[qno + 1]]
                  Inew = I4[lims4[qno] : lims4[qno + 1]]
                  assert set(Iref) == set(
                      Inew
                  ), "q %d ref %s new %s" % (
                      qno,
                      Iref,
                      Inew,
                  )
  
imports: from __future__ import absolute_import, division, print_function
  import unittest
  import faiss
  import numpy
  from common_faiss_tests import Randu10k, get_dataset_2, Randu10kUnbalanced
label_desc: Use image node_id 3 for calling the TestSQFlavors obj's underlying member method code with example usage: obj.subtest(mt) without return types