code: def subtest_8bit_direct(self, metric_type, d):
      xt, xb, xq = get_dataset_2(d, 500, 1000, 30)
  
      # rescale everything to get integer
      tmin, tmax = xt.min(), xt.max()
  
      def rescale(x):
          x = np.floor((x - tmin) * 256 / (tmax - tmin))
          x[x < 0] = 0
          x[x > 255] = 255
          return x
  
      xt = rescale(xt)
      xb = rescale(xb)
      xq = rescale(xq)
  
      gt_index = faiss.IndexFlat(d, metric_type)
      gt_index.add(xb)
      Dref, Iref = gt_index.search(xq, 10)
  
      index = faiss.IndexScalarQuantizer(
          d, faiss.ScalarQuantizer.QT_8bit_direct, metric_type
      )
      index.add(xb)
      D, I = index.search(xq, 10)
  
      assert np.all(I == Iref)
      assert np.all(D == Dref)
  
      # same, with IVF
  
      nlist = 64
      quantizer = faiss.IndexFlat(d, metric_type)
  
      gt_index = faiss.IndexIVFFlat(quantizer, d, nlist, metric_type)
      gt_index.nprobe = 4
      gt_index.train(xt)
      gt_index.add(xb)
      Dref, Iref = gt_index.search(xq, 10)
  
      index = faiss.IndexIVFScalarQuantizer(
          quantizer,
          d,
          nlist,
          faiss.ScalarQuantizer.QT_8bit_direct,
          metric_type,
      )
      index.nprobe = 4
      index.by_residual = False
      index.train(xt)
      index.add(xb)
      D, I = index.search(xq, 10)
  
      assert np.all(I == Iref)
      assert np.all(D == Dref)
  
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 1 for calling the TestSQByte obj's underlying member method code with example usage: obj.subtest_8bit_direct(metric_type, d) and returns: x